-- 
-- Face Melter Reloaded
-- By Draxios of US-Stormrage
-- Based on Original Face Melter by Etherwind of US-Darkspear Creds to Falie, aka Drescan or Aytherine
--

-- Our base array
FaceMelter = {}

-- Face Melter variables NOT SAVED - placeholders, array creation, etc.
FaceMelter.versionNumber = 4.030
FaceMelter.currentTarget = ""
FaceMelter.currentSpell = ""
FaceMelter.lastTarget = ""
FaceMelter.VTTarget = "" -- used for VT tracking as there's no succeed on cast,
FaceMelter.npcList = {} -- {guid, name}
FaceMelter.painList = {}  -- {guid, GetTime}
FaceMelter.touchList = {} -- {guid, GetTime}
FaceMelter.devouringList = {} -- {guid, GetTime}
FaceMelter.painHaste = {}  -- {guid, trueHaste}
FaceMelter.touchHaste = {} -- {guid, trueHaste}
FaceMelter.devouringHaste = {} -- {guid, trueHaste}
FaceMelter.painInterval = {} -- {guid, TickInterval}
FaceMelter.devouringInterval = {} -- {guid, TickInterval}
FaceMelter.touchInterval = {} -- {guid, TickInterval}
FaceMelter.blastTime = 0
FaceMelter.deathTime = 0
FaceMelter.timeSinceLastUpdate = 0
FaceMelter.blastCooldown = 8
FaceMelter.painDuration = 18
FaceMelter.devouringTime = 0
FaceMelter.spellHaste = GetCombatRatingBonus(20)
FaceMelter.hasteModifier = 0
FaceMelter.trueHaste = 0
FaceMelter.touchTimer = 0
FaceMelter.shouldCheckStuff = true;
FaceMelter.painRemaining = 3
FaceMelter.touchRemaining = 3
FaceMelter.devouringRemaining = 3
FaceMelter.vamptouchcasttimer = 1.5
FaceMelter.flayCastTime = 3
FaceMelter.hasVE = ""
FaceMelter.hasFORM = ""
FaceMelter.DECount = 0
FaceMelter.OrbCount = 0

function FMgetglobaletSpellNameByID(spellID)
	if (spellID == nil) then
		return nil
	end
		local spellName, _, _, _, _, _, _, _, _ = GetSpellInfo(spellID)
	return spellName	
end

FaceMelter.L = {
  ["Heroism"] = "Heroism",
  ["Bloodlust"] = "Bloodlust",
  ["Berserking"] = "Berserking",
  ["Time Warp"] = "Time Warp",
  ["Dark Intent"] = "Dark Intent",
  ["Shadowform"] = "Shadowform",
  ["Vampiric Embrace"] = "Vampiric Embrace",
  ["Dark Evangelism"] = "Dark Evangelism",
  ["Archangel"] = "Archangel",
  ["Mind Flay"] = "Mind Flay",
}

local language = GetLocale();
    FaceMelter.L["Heroism"] = FMgetglobaletSpellNameByID(32182)
    FaceMelter.L["Bloodlust"] = FMgetglobaletSpellNameByID(2825)
    FaceMelter.L["Berserking"] = FMgetglobaletSpellNameByID(26297)
    FaceMelter.L["Time Warp"] = FMgetglobaletSpellNameByID(80353)
    FaceMelter.L["Dark Intent"] = FMgetglobaletSpellNameByID(85767)
    FaceMelter.L["Shadowform"] = FMgetglobaletSpellNameByID(15473)
    FaceMelter.L["Vampiric Embrace"] = FMgetglobaletSpellNameByID(15286)
    FaceMelter.L["Dark Evangelism"] = FMgetglobaletSpellNameByID(87117)
    FaceMelter.L["Mind Flay"] = FMgetglobaletSpellNameByID(48156)
    FaceMelter.L["Mind Blast"] = FMgetglobaletSpellNameByID(8092)
    FaceMelter.L["Inner Fire"] = FMgetglobaletSpellNameByID(588)
    FaceMelter.L["Inner Will"] = FMgetglobaletSpellNameByID(73413)
    FaceMelter.L["Shadow Word: Pain"] = FMgetglobaletSpellNameByID(589)
    FaceMelter.L["Shadow Word: Death"] = FMgetglobaletSpellNameByID(32379)
    FaceMelter.L["Devouring Plague"] = FMgetglobaletSpellNameByID(2944)

FaceMelter.playerName = UnitName("player");

FaceMelter.textureList = {
  ["VT"] = GetSpellTexture("Vampiric Touch"),
  ["SWP"] = GetSpellTexture("Shadow Word: Pain"),
  ["MB"] = GetSpellTexture("Mind Blast"),
  ["SWD"] = GetSpellTexture("Shadow Word: Death"),
  ["FORM"] = GetSpellTexture("Shadowform"),
  ["FIEND"] = GetSpellTexture("Shadowfiend"),
  ["MF"] = GetSpellTexture("Mind Flay"),
  ["MS"] = GetSpellTexture("Mind Spike"),
  ["VE"] = GetSpellTexture("Vampiric Embrace"),
  ["DP"] = GetSpellTexture("Devouring Plague"), 
  ["DA"] = GetSpellTexture("Archangel"), 
  ["IF"] = GetSpellTexture("Inner Fire"), 
  ["IW"] = GetSpellTexture("Inner Will"), 
  ["Dispersion"] = GetSpellTexture("Dispersion"), 
  ["last"] = nil,
  ["current"] = nil,
  ["next"] = nil,
  ["highlight"] = nil,
}

FaceMelter.spellList = {
  ["last"] = "",
  ["current"] = "",
  ["next"] = "",
  ["third"] = "",
}

-- Our sneaky frame to watch for events ... checks FaceMelter.events[] for the function.  Passes all args.
FaceMelter.eventFrame = CreateFrame("Frame")
FaceMelter.eventFrame:SetScript("OnEvent", function(self, event, ...)
  FaceMelter.events[event](...)
end)

FaceMelter.eventFrame:RegisterEvent("ADDON_LOADED")
FaceMelter.eventFrame:RegisterEvent("PLAYER_LOGIN")

-- Define our Event Handlers here
FaceMelter.events = {}

function FaceMelter.events.PLAYER_LOGIN()
  FaceMelter.playerName = UnitName("player");
  FaceMelter.textureList["VT"] = GetSpellTexture("Vampiric Touch")
  FaceMelter.textureList["SWP"] = GetSpellTexture("Shadow Word: Pain")
  FaceMelter.textureList["MB"] = GetSpellTexture("Mind Blast")
  FaceMelter.textureList["SWD"] = GetSpellTexture("Shadow Word: Death")
  FaceMelter.textureList["FORM"] = GetSpellTexture("Shadowform")
  FaceMelter.textureList["FIEND"] = GetSpellTexture("Shadowfiend")
  FaceMelter.textureList["MF"] = GetSpellTexture("Mind Flay")
  FaceMelter.textureList["MS"] = GetSpellTexture("Mind Spike")
  FaceMelter.textureList["VE"] = GetSpellTexture("Vampiric Embrace")
  FaceMelter.textureList["DP"] = GetSpellTexture("Devouring Plague")
  FaceMelter.textureList["DA"] = GetSpellTexture("Archangel")
  FaceMelter.textureList["IF"] = GetSpellTexture("Inner Fire")
  FaceMelter.textureList["IW"] = GetSpellTexture("Inner Will")
  FaceMelter.textureList["DISP"] = GetSpellTexture("Dispersion")
end

function FaceMelter.events.ADDON_LOADED(addon)
  if addon ~= "FaceMelter" then return end
  local _,playerClass = UnitClass("player")
  local playerLevel = UnitLevel("player")
  if playerClass ~= "PRIEST" or playerLevel < 80 then
    print("Character must be a Priest of at least level 80 to load this FaceMelter.  Disabling...")
    return 
  end

  -- Figure out if we're a Goblin now to save the overhead later, since this will not change after loading
  local _,raceEn = UnitRace("player")
  if raceEn == "Goblin" then
    FaceMelter.racialHaste = 1.01
  else
    FaceMelter.racialHaste = 1
  end

  -- Default saved variables
  if not facemelterdb then 
	facemelterdb = {} -- fresh start
  end
  if facemelterdb.useMB == nil then facemelterdb.useMB = true end
  if facemelterdb.useDeath == nil then facemelterdb.useDeath = true end
  if facemelterdb.useSpike == nil then facemelterdb.useSpike = false end
  if facemelterdb.useFORM == nil then facemelterdb.useFORM = true end
  if facemelterdb.useFIEND == nil then facemelterdb.useFIEND = true end
  if facemelterdb.useVE == nil then facemelterdb.useVE = true end
  if facemelterdb.useDA == nil then facemelterdb.useDA = false end
  if facemelterdb.useIF == nil then facemelterdb.useIF = true end
  if facemelterdb.useIW == nil then facemelterdb.useIW = false end
  if facemelterdb.useDISP == nil then facemelterdb.useDISP = false end
  if not facemelterdb.scale then facemelterdb.scale = 1 end
  if not facemelterdb.hideSuggester then facemelterdb.hideSuggester = false end
  if not facemelterdb.hideButtons then facemelterdb.hideButtons = false end
  if not facemelterdb.minOrbs then facemelterdb.minOrbs = 0 end
  if not facemelterdb.miniOptionsAlpha then facemelterdb.miniOptionsAlpha = 1 end
  if not facemelterdb.healthPercent then facemelterdb.healthPercent = 50 end
  if not facemelterdb.executeHealth then facemelterdb.executeHealth = 25 end
  if not facemelterdb.deathMana then facemelterdb.deathMana = 50 end
  if not facemelterdb.dispersionMana then facemelterdb.dispersionMana = 50 end
  if not facemelterdb.locked then facemelterdb.locked = false end
  if not facemelterdb.dotTolerance then facemelterdb.dotTolerance = 30 end
  if not facemelterdb.empoweredRemaining then facemelterdb.empoweredRemaining = 10 end
  if not facemelterdb.x then facemelterdb.x = 100 end
  if not facemelterdb.y then facemelterdb.y = 100 end
  if not facemelterdb.pri then facemelterdb.pri = {} end
  if not facemelterdb.pri[1] then facemelterdb.pri[1] = "FORM" end
  if not facemelterdb.pri[2] then facemelterdb.pri[2] = "VE" end
  if not facemelterdb.pri[3] then facemelterdb.pri[3] = "SWP" end
  if not facemelterdb.pri[4] then facemelterdb.pri[4] = "FIEND" end
  if not facemelterdb.pri[5] then facemelterdb.pri[5] = "DA" end
  if not facemelterdb.pri[6] then facemelterdb.pri[6] = "VT" end
  if not facemelterdb.pri[7] then facemelterdb.pri[7] = "DP" end
  if not facemelterdb.pri[8] then facemelterdb.pri[8] = "SWD" end
  if not facemelterdb.pri[9] then facemelterdb.pri[9] = "MB" end
  if not facemelterdb.pri[10] then facemelterdb.pri[10] = "MS" end
  if not facemelterdb.pri[11] then facemelterdb.pri[11] = "IF" end
  if not facemelterdb.pri[12] then facemelterdb.pri[12] = "DISP" end
  if not facemelterdb.priRev then facemelterdb.priRev = {
	["MS"] = 10,
	["FORM"] = 1,
	["FIEND"] = 4,
	["SWD"] = 8,
	["SWP"] = 3,
	["DP"] = 7,
	["MB"] = 9,
	["VT"] = 6,
	["VE"] = 2,
	["DA"] = 5,
	["IF"] = 11,
	["DISP"] = 12,}
  end

  -- Create GUI
  FaceMelter:CreateGUI()
  FaceMelter.displayFrame:SetScale(facemelterdb.scale)
  FaceMelter.gcdbar:Hide()
  FaceMelter.eventFrame:RegisterEvent("ACTIONBAR_UPDATE_COOLDOWN")
  
  -- Create Options Frame
  FaceMelter:CreateOptionFrame()
  if facemelterdb.locked then
    FaceMelter.displayFrame:SetScript("OnMouseDown", nil)
    FaceMelter.displayFrame:SetScript("OnMouseUp", nil)
    FaceMelter.displayFrame:SetScript("OnDragStop", nil)
    FaceMelter.displayFrame:SetBackdropColor(0, 0, 0, 0)
	FaceMelter.displayFrame:EnableMouse(false)
  else
    FaceMelter.displayFrame:SetScript("OnMouseDown", function(self) self:StartMoving() end)
    FaceMelter.displayFrame:SetScript("OnMouseUp", function(self) self:StopMovingOrSizing() end)
    FaceMelter.displayFrame:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
    FaceMelter.displayFrame:SetBackdropColor(0, 0, 0, .4)
	FaceMelter.displayFrame:EnableMouse(true)
  end
  
  FaceMelter:DetermineTrueShowHide()
  FaceMelter:EvalGUIShowHide()
  -- Register for Slash Commands

--  SlashCmdList["FACEMELTER"] = FaceMelter.Options
  SlashCmdList["FACEMELTER"] = FaceMelter.Command
  SLASH_FACEMELTER1 = "/facemelter"
  SLASH_FACEMELTER2 = "/fm"
  
  -- Register for Function Events
  FaceMelter.eventFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  FaceMelter.eventFrame:RegisterEvent("PLAYER_TARGET_CHANGED")
  FaceMelter.eventFrame:RegisterEvent("PLAYER_REGEN_ENABLED") -- Left combat, clean up all enemy GUIDs
  FaceMelter.eventFrame:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED")
  FaceMelter.eventFrame:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
  FaceMelter.eventFrame:RegisterEvent("UNIT_SPELLCAST_CHANNEL_STOP")
  FaceMelter.eventFrame:RegisterEvent("UNIT_INVENTORY_CHANGED")
  FaceMelter.eventFrame:RegisterEvent("CHARACTER_POINTS_CHANGED")
end

function FaceMelter.events.COMBAT_LOG_EVENT_UNFILTERED(timestamp, event, srcGUID, srcName, srcFlags, dstGUID, dstName, dstFlags, ...)
  if srcName == FaceMelter.playerName then
    if facemelterdb.truehide == false then
      if event == "SPELL_CAST_START" then
        local _, spellName = ...
        local guid = UnitGUID("target")
        if spellName == "Mind Blast" then
          FaceMelter.currentSpell = "MB"
          if(FaceMelter.textureList["highlight"]) then FaceMelter.textureList["highlight"]:SetAlpha(0) end
          FaceMelter.npcList[guid] = UnitName("target")
          FaceMelter:PushDisplay()
        elseif spellName == "Vampiric Touch" then
          FaceMelter.currentSpell = "VT"
          if(FaceMelter.textureList["highlight"]) then FaceMelter.textureList["highlight"]:SetAlpha(0) end
          FaceMelter.npcList[guid] = UnitName("target")
          FaceMelter.VTTarget = guid
          FaceMelter:PushDisplay()
        elseif spellName == "Mind Spike" then
          FaceMelter.currentSpell = "MS"
          if(FaceMelter.textureList["highlight"]) then FaceMelter.textureList["highlight"]:SetAlpha(0) end
          FaceMelter.npcList[guid] = UnitName("target")
          FaceMelter:PushDisplay()
          -- reset DoTs
          FaceMelter.painList[guid] = 0
          FaceMelter.touchList[guid] = 0
          FaceMelter.devouringList[guid] = 0
        end
      elseif event == "SPELL_CAST_SUCCESS" then
        local _, spellName = ...  
        if spellName == "Shadow Word: Pain" then
          FaceMelter.currentSpell = "SWP"
          if(FaceMelter.textureList["highlight"]) then FaceMelter.textureList["highlight"]:SetAlpha(0) end
          FaceMelter.npcList[dstGUID] = dstName
          FaceMelter.painList[dstGUID] = GetTime()
          FaceMelter.painHaste[dstGUID] = FaceMelter.trueHaste
          FaceMelter:PushDisplay()
        elseif spellName == "Devouring Plague" then
          FaceMelter.currentSpell = "DP"
          if(FaceMelter.textureList["highlight"]) then FaceMelter.textureList["highlight"]:SetAlpha(0) end
          FaceMelter.npcList[dstGUID] = dstName
          FaceMelter.devouringList[dstGUID] = GetTime()
          FaceMelter.devouringHaste[dstGUID] = FaceMelter.trueHaste
          FaceMelter:PushDisplay()
        elseif spellName == "Shadow Word: Death" then
          FaceMelter.currentSpell = "SWD"
          if(FaceMelter.textureList["highlight"]) then FaceMelter.textureList["highlight"]:SetAlpha(0) end
          FaceMelter.npcList[dstGUID] = dstName
          FaceMelter.deathTime = GetTime()
          FaceMelter:PushDisplay()
        elseif spellName == "Shadowform" then
          FaceMelter.currentSpell = "FORM"
          if(FaceMelter.textureList["highlight"]) then FaceMelter.textureList["highlight"]:SetAlpha(0) end
          FaceMelter.npcList[dstGUID] = dstName
          FaceMelter:PushDisplay()
        elseif spellName == "Shadowfiend" then
          FaceMelter.currentSpell = "FIEND"
          if(FaceMelter.textureList["highlight"]) then FaceMelter.textureList["highlight"]:SetAlpha(0) end
          FaceMelter.npcList[dstGUID] = dstName
          FaceMelter:PushDisplay()
        elseif spellName == "Archangel" then
          FaceMelter.currentSpell = "DA"
          if(FaceMelter.textureList["highlight"]) then FaceMelter.textureList["highlight"]:SetAlpha(0) end
          FaceMelter.npcList[dstGUID] = dstName
          FaceMelter:PushDisplay()
        elseif spellName == "Dark Archangel" then
          FaceMelter.currentSpell = "DA"
          if(FaceMelter.textureList["highlight"]) then FaceMelter.textureList["highlight"]:SetAlpha(0) end
          FaceMelter.npcList[dstGUID] = dstName
          FaceMelter:PushDisplay()
        elseif spellName == "Inner Fire" then
          FaceMelter.currentSpell = "IF"
          if(FaceMelter.textureList["highlight"]) then FaceMelter.textureList["highlight"]:SetAlpha(0) end
          FaceMelter.npcList[dstGUID] = dstName
          FaceMelter:PushDisplay()
        elseif spellName == "Inner Will" then
          FaceMelter.currentSpell = "IF"
          if(FaceMelter.textureList["highlight"]) then FaceMelter.textureList["highlight"]:SetAlpha(0) end
          FaceMelter.npcList[dstGUID] = dstName
          FaceMelter:PushDisplay()
        elseif spellName == "Dispersion" then
          FaceMelter.currentSpell = "DISP"
          if(FaceMelter.textureList["highlight"]) then FaceMelter.textureList["highlight"]:SetAlpha(0) end
          FaceMelter.npcList[dstGUID] = dstName
          FaceMelter:PushDisplay()
        elseif spellName == "Mind Flay" then
          FaceMelter.currentSpell = "MF"
          if(FaceMelter.textureList["highlight"]) then FaceMelter.textureList["highlight"]:SetAlpha(0) end
          FaceMelter.npcList[dstGUID] = dstName
          FaceMelter.flayTime = GetTime()
          FaceMelter:PushDisplay()
        end   
	  elseif event == "SPELL_AURA_APPLIED" then
		local _, spellName = ...  
		 if spellName == "Mind Flay" then
          FaceMelter.currentSpell = "MF"
          if(FaceMelter.textureList["highlight"]) then FaceMelter.textureList["highlight"]:SetAlpha(0) end
          FaceMelter.npcList[dstGUID] = dstName
          FaceMelter.flayTime = GetTime()
		  if FaceMelter.painList[dstGUID] ~= nil then -- refresh pain if it's up on target
		    if GetTime() - FaceMelter.painList[dstGUID] < FaceMelter.painDuration then
			  FaceMelter.painList[dstGUID] = GetTime()
			end
		  end
          FaceMelter:PushDisplay()
		 end
      elseif event == "SPELL_MISSED" then -- aww we get resisted, we only care if it's a debuff though
        local _, spellName = ...  
        if spellName == "Shadow Word: Pain" then
          FaceMelter.painList[dstGUID] = 0
          FaceMelter:PushDisplay()
        elseif spellName == "Vampiric Touch" then
          FaceMelter.touchList[dstGUID] = 0
          FaceMelter:PushDisplay()
        elseif spellName == "Devouring Plague" then
          FaceMelter.devouringList[dstGUID] = 0
          FaceMelter:PushDisplay()
        end    
      end
	end
  end  
end

function FaceMelter.events.PLAYER_TARGET_CHANGED(...) 
  FaceMelter:DetermineTrueShowHide()
  FaceMelter:EvalGUIShowHide()
  -- target changed, set last target, update current target, will be nil if no target
  FaceMelter.lastTarget = FaceMelter.currentTarget
  FaceMelter.currentTarget = UnitGUID("target")
  if UnitName("target") == nil or UnitIsFriend("player","target") ~= nil or UnitHealth("target") == 0 then
    FaceMelter.displayFrame_last:Hide()
    FaceMelter.displayFrame_current:Hide()
    FaceMelter.displayFrame_next:Hide()
    FaceMelter.displayFrame_currentHighlight:Hide()
  else
    FaceMelter.displayFrame_currentHighlight:Show()
    FaceMelter.displayFrame_last:Show()
    FaceMelter.displayFrame_current:Show()
    FaceMelter.displayFrame_next:Show()
  end
  FaceMelter:PushDisplay()
  FaceMelter:DecideSpells()
end

function FaceMelter.events.PLAYER_REGEN_ENABLED(...)
  -- We have left combat, clean up GUIDs
  FaceMelter.npcList = {} -- {guid, name}
  FaceMelter.painList = {}  -- {guid, GetTime}
  FaceMelter.touchList = {} -- {guid, GetTime}
  FaceMelter.devouringList = {} -- {guid, GetTime}
  FaceMelter.painHaste = {}  -- {guid, trueHaste}
  FaceMelter.touchHaste = {} -- {guid, trueHaste}
  FaceMelter.devouringHaste = {} -- {guid, trueHaste}
  FaceMelter.painInterval = {}  -- {guid, TickInterval}
  FaceMelter.touchInterval = {} -- {guid, TickInterval}
  FaceMelter.devouringInterval = {} -- {guid, TickInterval}
  FaceMelter:DetermineTrueShowHide()
  FaceMelter:EvalGUIShowHide()
end

function FaceMelter.events.UNIT_SPELLCAST_INTERRUPTED(name, spellName, ...)
  if name == "player" then
    if spellName == "Mind Blast" then
      FaceMelter.blastTime = 0
    elseif spellName == "Vampiric Touch" and FaceMelter.touchList[FaceMelter.VTTarget] ~= nil then
      FaceMelter.touchList[FaceMelter.VTTarget] = 0
    end
    FaceMelter.currentSpell = ""
  end
  FaceMelter:DecideSpells()
end

function FaceMelter.events.UNIT_SPELLCAST_SUCCEEDED(name, spellName, ...)
  if name == "player" and spellName ~= "Mind Flay" then
    if spellName == "Mind Blast" then
      FaceMelter.blastTime = GetTime()
      if(FaceMelter.textureList["highlight"]) then FaceMelter.textureList["highlight"]:SetAlpha(1) end
    elseif spellName == "Vampiric Touch" then
      FaceMelter.touchList[FaceMelter.VTTarget] = GetTime() -- set the time for current time
      FaceMelter.touchHaste[FaceMelter.VTTarget] = FaceMelter.trueHaste
      FaceMelter:DecideSpells()
      if(FaceMelter.textureList["highlight"]) then FaceMelter.textureList["highlight"]:SetAlpha(1) end
    end
   FaceMelter.currentSpell = ""
  end  
end

function FaceMelter.events.UNIT_SPELLCAST_CHANNEL_STOP(name, spellName, ...)
    if name == "player" and spellName == "Mind Flay" then
    if(FaceMelter.textureList["highlight"]) then FaceMelter.textureList["highlight"]:SetAlpha(1) end
    FaceMelter.currentSpell = ""
  end
end

function FaceMelter.events.UNIT_INVENTORY_CHANGED(name)
  if name == "player" then
  end
end

function FaceMelter.events.CHARACTER_POINTS_CHANGED()
end

-- End Event Handlers

function FaceMelter:CreateGUI()

  local displayFrame = CreateFrame("Frame","FaceMelterDisplayFrame",UIParent)
  displayFrame:SetFrameStrata("BACKGROUND")
  displayFrame:SetWidth(300)
  displayFrame:SetHeight(110)
  displayFrame:SetBackdrop({
          bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 32,
  			})
  displayFrame:SetBackdropColor(0, 0, 0, .4)
  displayFrame:EnableMouse(true)
  displayFrame:SetMovable(true)
  displayFrame:SetClampedToScreen(true)
  displayFrame:SetScript("OnMouseDown", function(self) self:StartMoving() end)
  displayFrame:SetScript("OnMouseUp", function(self) self:StopMovingOrSizing() end)
  displayFrame:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
  displayFrame:SetPoint("CENTER",-200,-200)
  
  local displayFrame_last = CreateFrame("Frame","$parent_last", FaceMelterDisplayFrame)
  local displayFrame_currentHighlight = CreateFrame("Frame","$parent_currentHighlight", FaceMelterDisplayFrame)
  local displayFrame_current = CreateFrame("Frame","$parent_current", FaceMelterDisplayFrame_currentHighlight)
  local displayFrame_next = CreateFrame("Frame","$parent_next", FaceMelterDisplayFrame)
  
  displayFrame_last:SetWidth(70)
  displayFrame_current:SetWidth(70)
  displayFrame_currentHighlight:SetWidth(80)
  displayFrame_next:SetWidth(70)
  
  displayFrame_last:SetHeight(70)
  displayFrame_current:SetHeight(70)
  displayFrame_currentHighlight:SetHeight(80)
  displayFrame_next:SetHeight(70)
  
  displayFrame_last:SetPoint("TOPLEFT", 25, -20)
  displayFrame_currentHighlight:SetPoint("TOPLEFT", 110, -15)
  displayFrame_current:SetPoint("TOPLEFT", 5, -5)
  displayFrame_next:SetPoint("TOPLEFT", 205, -20)
    
  local t = displayFrame_last:CreateTexture(nil,"BACKGROUND")
  t:SetTexture(nil)
  t:SetAllPoints(displayFrame_last)
  t:SetAlpha(.2)
  displayFrame_last.texture = t
  FaceMelter.textureList["last"] = t
  
  t = displayFrame_current:CreateTexture(nil,"BACKGROUND")
  t:SetTexture(nil)
  t:ClearAllPoints()
  t:SetAllPoints(displayFrame_current)
  displayFrame_current.texture = t
  FaceMelter.textureList["current"] = t
  
  t = displayFrame_next:CreateTexture(nil,"BACKGROUND")
  t:SetTexture(nil)
  t:SetAllPoints(displayFrame_next)
  t:SetAlpha(.5)
  displayFrame_next.texture = t
  FaceMelter.textureList["next"] = t
  
  t = displayFrame_currentHighlight:CreateTexture(nil,"BACKGROUND")
  t:SetTexture(.1,.5,.1)
  t:SetAllPoints(displayFrame_currentHighlight)
  t:SetAlpha(0)
  displayFrame_currentHighlight.texture = t
  FaceMelter.textureList["highlight"] = t
    
  displayFrame:SetScript("OnUpdate", function(self, elapsed)
    FaceMelter:OnUpdate(elapsed)
  end)
  
  local cooldownFrame = CreateFrame("Cooldown","$parent_cooldown", FaceMelterDisplayFrame_current)
  cooldownFrame:SetHeight(70)
  cooldownFrame:SetWidth(70)
  cooldownFrame:ClearAllPoints()
  cooldownFrame:SetPoint("CENTER", displayFrame_current, "CENTER", 0, 0)
  
  FaceMelter.displayFrame = displayFrame
  FaceMelter.displayFrame_last = displayFrame_last
  FaceMelter.displayFrame_current = displayFrame_current
  FaceMelter.displayFrame_next = displayFrame_next
  FaceMelter.displayFrame_currentHighlight = displayFrame_currentHighlight
  FaceMelter.cooldownFrame = cooldownFrame
  
  local gcdbar = CreateFrame('Frame', 'FaceMelterGCDBar', UIParent)
  gcdbar:SetFrameStrata('HIGH')
  gcdbar:SetScript('OnShow', function() FaceMelter.OnShowGCD() end)
  gcdbar:SetScript('OnHide', function() FaceMelter.OnHideGCD() end)
  local gcdspark = gcdbar:CreateTexture(nil, 'DIALOG')
  FaceMelter.gcdstart = 0
  FaceMelter.gcdduration = 0
  gcdbar:ClearAllPoints()
  gcdbar:SetHeight(10)
  gcdbar:SetWidth(300)
  gcdbar:SetPoint("BOTTOM", FaceMelterDisplayFrame, "TOP", 0, 0)
  gcdspark:SetTexture("Interface\\CastingBar\\UI-CastingBar-Spark")
  gcdspark:SetVertexColor(1, 1, 1)
  gcdspark:SetBlendMode('ADD')
  gcdspark:SetWidth(25)
  gcdspark:SetHeight(10)
  FaceMelter.gcdbar = gcdbar
  FaceMelter.gcdspark = gcdspark
  
  local displayFrame_options = CreateFrame("Frame","$parent_options", FaceMelterDisplayFrame)
  displayFrame_options:SetWidth(70)
  displayFrame_options:SetHeight(110)
  displayFrame_options:SetPoint("BOTTOMLEFT", 0, -0)

  local MBString = displayFrame_options:CreateFontString("FaceMelter_MBString","OVERLAY","GameFontNormal")
  local MBCheck = CreateFrame("CheckButton", "$parent_vecb", displayFrame_options, "UICheckButtonTemplate")
  MBString:SetText("MB")
  MBCheck:SetWidth(16)
  MBCheck:SetHeight(16)
  MBCheck:SetScript("OnClick", function() FaceMelter:ToggleMB() end)
  MBString:SetPoint("BOTTOMLEFT", 16, 0)
  MBCheck:SetPoint("BOTTOMLEFT", 0, -1)
  MBCheck:SetChecked(FaceMelter:GetMB())
  FaceMelter.MBCheck = MBCheck

  local SWDString = displayFrame_options:CreateFontString("FaceMelter_SWDString","OVERLAY","GameFontNormal")
  local SWDCheck = CreateFrame("CheckButton", "$parent_swdcb", displayFrame_options, "UICheckButtonTemplate")
  SWDString:SetText("SW:D")
  SWDCheck:SetWidth(16)
  SWDCheck:SetHeight(16)
  SWDCheck:SetScript("OnClick", function() FaceMelter:ToggleDeath() end)
  SWDString:SetPoint("BOTTOMRIGHT", 214, 0)
  SWDCheck:SetPoint("BOTTOMRIGHT", 230, -1)
  SWDCheck:SetChecked(FaceMelter:GetDeath())
  FaceMelter.SWDCheck = SWDCheck  

  local MSString = displayFrame_options:CreateFontString("FaceMelter_SWDString","OVERLAY","GameFontNormal")
  local MSCheck = CreateFrame("CheckButton", "$parent_vecb", displayFrame_options, "UICheckButtonTemplate")
  MSString:SetText("MS")
  MSCheck:SetWidth(16)
  MSCheck:SetHeight(16)
  MSCheck:SetScript("OnClick", function() FaceMelter:ToggleMS() end)
  MSString:SetPoint("BOTTOM", 120, 0)
  MSCheck:SetPoint("BOTTOM", 100, -1)
  MSCheck:SetChecked(FaceMelter:GetMS())
  FaceMelter.MSCheck = MSCheck

  local DISPString = displayFrame_options:CreateFontString("FaceMelter_DISPString","OVERLAY","GameFontNormal")
  local DISPCheck = CreateFrame("CheckButton", "$parent_formcb", displayFrame_options, "UICheckButtonTemplate")
  DISPString:SetText("DISP")
  DISPCheck:SetWidth(16)
  DISPCheck:SetHeight(16)
  DISPCheck:SetScript("OnClick", function() FaceMelter:ToggleDispersion() end)
  DISPString:SetPoint("TOPLEFT", 16, 0)
  DISPCheck:SetPoint("TOPLEFT", 0, -1)
  DISPCheck:SetChecked(FaceMelter:GetDispersion())
  FaceMelter.DISPCheck = DISPCheck

  local FIENDString = displayFrame_options:CreateFontString("FaceMelter_FIENDString","OVERLAY","GameFontNormal")
  local FIENDCheck = CreateFrame("CheckButton", "$parent_fiendcb", displayFrame_options, "UICheckButtonTemplate")
  FIENDString:SetText("FIEND")
  FIENDCheck:SetWidth(16)
  FIENDCheck:SetHeight(16)
  FIENDCheck:SetScript("OnClick", function() FaceMelter:ToggleFIEND() end)
  FIENDString:SetPoint("TOP", 125, 0)
  FIENDCheck:SetPoint("TOP", 100, -1)
  FIENDCheck:SetChecked(FaceMelter:GetFIEND())
  FaceMelter.FIENDCheck = FIENDCheck

  local IFString = displayFrame_options:CreateFontString("FaceMelter_IFString","OIFRLAY","GameFontNormal")
  local IFCheck = CreateFrame("CheckButton", "$parent_vampecb", displayFrame_options, "UICheckButtonTemplate")
  IFString:SetText("IF")
  IFCheck:SetWidth(16)
  IFCheck:SetHeight(16)
  IFCheck:SetScript("OnClick", function() FaceMelter:ToggleIF() end)
  IFString:SetPoint("TOPRIGHT", 214, 0)
  IFCheck:SetPoint("TOPRIGHT", 230, -1)
  IFCheck:SetChecked(FaceMelter:GetIF())
  FaceMelter.IFCheck = IFCheck

  local IWString = displayFrame_options:CreateFontString("FaceMelter_IWString","OIWRLAY","GameFontNormal")
  local IWCheck = CreateFrame("CheckButton", "$parent_vampecb", displayFrame_options, "UICheckButtonTemplate")
  IWString:SetText("IW")
  IWCheck:SetWidth(16)
  IWCheck:SetHeight(16)
  IWCheck:SetScript("OnClick", function() FaceMelter:ToggleIW() end)
  IWString:SetPoint("RIGHT", 214, 0)
  IWCheck:SetPoint("RIGHT", 230, -1)
  IWCheck:SetChecked(FaceMelter:GetIW())
  FaceMelter.IWCheck = IWCheck

  local DAString = displayFrame_options:CreateFontString("FaceMelter_DAString","OVERLAY","GameFontNormal")
  local DACheck = CreateFrame("CheckButton", "$parent_dacb", displayFrame_options, "UICheckButtonTemplate")
  DAString:SetText("DA")
  DACheck:SetWidth(16)
  DACheck:SetHeight(16)
  DACheck:SetScript("OnClick", function() FaceMelter:ToggleDA() end)
  DAString:SetPoint("LEFT", 16, 0)
  DACheck:SetPoint("LEFT", 0, -1)
  DACheck:SetChecked(FaceMelter:GetDA())
  FaceMelter.DACheck = DACheck

  FaceMelter.displayFrame_options = displayFrame_options
  FaceMelter.displayFrame_options:SetAlpha(facemelterdb.miniOptionsAlpha)

  FaceMelter.displayFrame:Show()
end

function FaceMelter.OnHideGCD()
	FaceMelter.gcdbar:SetScript('OnUpdate', nil)
end

function FaceMelter.OnShowGCD()
	FaceMelter.gcdbar:SetScript('OnUpdate', function() FaceMelter.OnUpdateGCD() end)
end

function FaceMelter.OnUpdateGCD()
	FaceMelter.gcdspark:ClearAllPoints()
	local perc = (GetTime() - FaceMelter.gcdstart) / FaceMelter.gcdduration
	if perc > 1 then
	  if FaceMelter.currentSpell == "SWD" or FaceMelter.currentSpell == "SWP" or FaceMelter.currentSpell == "MB" then
            if(FaceMelter.textureList["highlight"]) then 
                FaceMelter.textureList["highlight"]:SetAlpha(1)
            end
	  end
		return FaceMelter.gcdbar:Hide()
	else
		FaceMelter.gcdspark:SetPoint('CENTER', FaceMelter.gcdbar, 'LEFT', 250 * perc, 0)
	end	
end

function FaceMelter.events.ACTIONBAR_UPDATE_COOLDOWN(...)
--  local start, dur = GetSpellCooldown("Shadow Word: Pain")
  local start, dur = GetSpellCooldown(589)
    if dur > 0 and FaceMelter.currentSpell == "MF" then
      FaceMelter.gcdstart = start
      FaceMelter.gcdduration = FaceMelter.flayCastTime
  	  FaceMelter.gcdbar:Show()
    elseif dur <= 0 then
 	  FaceMelter.gcdstart = start
  	  FaceMelter.gcdduration = dur
  	  FaceMelter.gcdbar:Show()
    end
end

function FaceMelter:OnUpdate(elapsed)
  FaceMelter.timeSinceLastUpdate = FaceMelter.timeSinceLastUpdate + elapsed; 
--force Alpha change after 2 Mind Flay ticks
  if (FaceMelter.currentSpell == "MF" and FaceMelter.spellList["current"] ~= "MF" and GetTime() - FaceMelter.flayTime > (FaceMelter.flayCastTime * .67)) then
    if(FaceMelter.textureList["highlight"]) then 
      FaceMelter.textureList["highlight"]:SetAlpha(1)
    end
  end
  if (FaceMelter.timeSinceLastUpdate > ((1.5/FaceMelter.trueHaste) * 0.5)) then
    FaceMelter:DecideSpells()
  end
end

function FaceMelter:PushDisplay()
  -- Move to the new spell to cast
  if FaceMelter.currentSpell == FaceMelter.spellList["current"] then
     FaceMelter.textureList["last"]:SetTexture(FaceMelter.textureList[FaceMelter.spellList["current"]])
     FaceMelter.textureList["current"]:SetTexture(FaceMelter.textureList[FaceMelter.spellList["next"]])
     FaceMelter.textureList["next"]:SetTexture(FaceMelter.textureList[FaceMelter.spellList["third"]])   
     FaceMelter.spellList["last"] = FaceMelter.spellList["current"]
     FaceMelter.spellList["current"] = FaceMelter.spellList["next"]
     FaceMelter.spellList["next"] = FaceMelter.spellList["third"]
     FaceMelter.spellList["third"] = ""
  end
  FaceMelter:DecideSpells()
end

function FaceMelter:DecideSpells() 
  FaceMelter:HasteCheck()
  FaceMelter:CheckStuff()
  FaceMelter.timeSinceLastUpdate = 0;
  if  UnitName("target") == nil or UnitIsFriend("player","target") ~= nil or UnitHealth("target") == 0 then
    return -- ignore the dead and friendly
  end
  local firstSpell = ""
  local secondSpell = ""
  local thirdSpell = ""
  local guid = UnitGUID("target")
  local currentTime = GetTime()
  local GCD = 1.5/FaceMelter.trueHaste
  if GCD < 1 then
      GCD = 1
  end
  if guid == nil then
    FaceMelter.textureList["last"]:SetTexture(nil)
    FaceMelter.textureList["current"]:SetTexture(nil)
    FaceMelter.textureList["next"]:SetTexture(nil)
    FaceMelter.spellList["last"] = ""
    FaceMelter.spellList["current"] = ""
    FaceMelter.spellList["next"] = ""
    FaceMelter.spellList["third"] = ""
    return
  end
    local painSecsElapsed = 9999
    local touchSecsElapsed = 9999
        
    for pri, spell in pairs(facemelterdb.pri) do
      if FaceMelter.currentSpell == spell then
        -- skip if we just cast the spell but it hasn't cleared yet
      else
        local timeUntilNext = 0
        if spell == "SWD" then
            -- experimental change to use actual spell cooldown
          if facemelterdb.useDeath then
            if UnitHealth("player") / UnitHealthMax("player") * 100 >= facemelterdb.healthPercent and (UnitHealth("target") / UnitHealthMax("target") * 100 <= facemelterdb.executeHealth or UnitMana("player") / UnitManaMax("player") * 100 <= facemelterdb.deathMana) then
              if GetSpellCooldown(32379) == GetSpellCooldown(589) then
                timeUntilNext = 0 --aka now
              else
              timeUntilNext = GetSpellCooldown(32379)
              end
            else
              timeUntilNext = 999 --aka never
            end
          else
            timeUntilNext = 999 --aka never
          end
        elseif spell == "SWP" then
          if FaceMelter.painList[guid] ~= nil then
            timeUntilNext = FaceMelter.painRemaining
          else
            timeUntilNext = 0 --aka now
          end
        elseif spell == "MB" then
          --if facemelterdb.useMB and FaceMelter.OrbCount >= facemelterdb.minOrbs then
		  if facemelterdb.useMB and FaceMelter.OrbCount >= facemelterdb.minOrbs and (FaceMelter.OrbCount == 3 or FaceMelter.EmpoweredDuration <= facemelterdb.empoweredRemaining or facemelterdb.minOrbs == 0) then	  
            -- experimental change to use actual spell cooldown
            if GetSpellCooldown(8092) == GetSpellCooldown(589) then
              timeUntilNext = 0 --aka now
            else
              timeUntilNext = GetSpellCooldown(8092)
            end
          else
          timeUntilNext = 999 --aka never
          end
        elseif spell == "MS" then
          if facemelterdb.useMS and FaceMelter.painList[guid] == nil and FaceMelter.touchList[guid] == nil and FaceMelter.devouringList[guid] == nil then
          timeUntilNext = 0
          else
          timeUntilNext = 999 --aka never
          end
        elseif spell == "VT" then
          if FaceMelter.touchList[guid] ~= nil then
            timeUntilNext = FaceMelter.touchRemaining - FaceMelter.vamptouchcasttimer
          end
        elseif spell == "DP" then
          if FaceMelter.devouringList[guid] ~= nil then
            timeUntilNext = FaceMelter.devouringRemaining
          end
        elseif spell == "FORM" then
          if FaceMelter.hasFORM == "" and facemelterdb.useFORM then
            timeUntilNext = 0
          else
            timeUntilNext = 999 --aka never
          end
        elseif spell == "IF" then
          if facemelterdb.useIF then
            if FaceMelter.hasIF == "" then
              timeUntilNext = 0
            else
              timeUntilNext = 999 --aka never
            end
          elseif facemelterdb.useIW then
            if FaceMelter.hasIW == "" then
              timeUntilNext = 0
            else
              timeUntilNext = 999 --aka never
            end
          else
            timeUntilNext = 999 --aka never
          end
        elseif spell == "VE" then
          if FaceMelter.hasVE == "" and facemelterdb.useVE then
            timeUntilNext = 0
          else
            timeUntilNext = 999 --aka never
          end
        elseif spell == "FIEND" then 
          if facemelterdb.useFIEND then
            if GetSpellCooldown(34433) == GetSpellCooldown(589) then
              timeUntilNext = 0 --aka now
            else
              timeUntilNext = GetSpellCooldown(34433)
            end
          else
            timeUntilNext = 999 --aka never
          end
        elseif spell == "DISP" then 
          if facemelterdb.useDISP and UnitMana("player") / UnitManaMax("player") * 100 <= facemelterdb.dispersionMana then
            if GetSpellCooldown(47585) == GetSpellCooldown(589) then
              timeUntilNext = 0 --aka now
            else
              timeUntilNext = GetSpellCooldown(47585)
            end
          else
            timeUntilNext = 999 --aka never
          end
        elseif spell == "DA" then
          if facemelterdb.useDA and FaceMelter.DECount == 5 and FaceMelter.touchRemaining >= FaceMelter.touchInterval[guid]*2 + FaceMelter.vamptouchcasttimer and FaceMelter.devouringRemaining >= FaceMelter.devouringInterval[guid]*2 then
            if GetSpellCooldown(87151) == GetSpellCooldown(589) then
              timeUntilNext = 0 --aka now
            else
              timeUntilNext = GetSpellCooldown(87151)
            end
          else
            timeUntilNext = 999 --aka never
          end
        end
        -- run our tests
        if timeUntilNext < GCD then
          if firstSpell == "" then
            firstSpell = spell
          elseif secondSpell == "" then
            secondSpell = spell
          elseif thirdSpell == "" then
            thirdSpell = spell
          end
        elseif timeUntilNext < GCD * 2 then
          if secondSpell == "" then
            secondSpell = spell
          elseif thirdSpell == "" then
            thirdSpell = spell
          end
        elseif timeUntilNext < GCD * 3 then
          if thirdSpell == "" then
            thirdSpell = spell
          end
        end  -- test ended
      end
    end  
    
    -- If still empty, fill in with MF unless previous global we MF'd
    if firstSpell == "" then
      firstSpell = "MF"
    end
    if secondSpell == "" and firstSpell ~= "MF" then
      secondSpell = "MF"
    end
    if thirdSpell == "" and secondSpell ~= "MF" then
      thirdSpell = "MF"
    end
    
    -- Update the spellList array - if we find a mismatch, report it, and update the texture
    if FaceMelter.spellList["current"] == firstSpell then
    else
      --DEFAULT_CHAT_FRAME:AddMessage("Mismatch current: " .. FaceMelter.spellList["current"] .. firstSpell);
      FaceMelter.spellList["current"] = firstSpell
      FaceMelter.textureList["current"]:SetTexture(FaceMelter.textureList[FaceMelter.spellList["current"]])
    end
    if FaceMelter.spellList["next"] == secondSpell then
    else
      --DEFAULT_CHAT_FRAME:AddMessage("Mismatch next: " .. FaceMelter.spellList["next"] .. secondSpell);
      FaceMelter.spellList["next"] = secondSpell
      FaceMelter.textureList["next"]:SetTexture(FaceMelter.textureList[FaceMelter.spellList["next"]])
    end
    FaceMelter.spellList["third"] = thirdSpell
    
    -- MF full length = 2 X GCD... SO....
    if firstSpell == "MF" and secondSpell == "MF" then
      FaceMelter.textureList["next"]:SetTexture(FaceMelter.textureList[FaceMelter.spellList["third"]])
      FaceMelter.spellList["next"] = FaceMelter.spellList["third"]
      FaceMelter.spellList["third"] = ""
    end
    
    if firstSpell == "MB" then
      FaceMelter.cooldownFrame:SetCooldown(FaceMelter.blastTime, FaceMelter.blastCooldown)
    elseif firstSpell == "SWD" then
      FaceMelter.cooldownFrame:SetCooldown(FaceMelter.deathTime, 10)
    end
end

function FaceMelter:HasteCheck()  
  local nameTalent, _, _, _, currentRank, _, _, _ = GetTalentInfo(3, 1)
  local darknessHaste = 1 + (currentRank * .01)
  local nameTalent, _, _, _, currentRank, _, _, _ = GetTalentInfo(3, 8)
  local shadowformHaste = 1 + (currentRank * .05)
  FaceMelter.spellHaste = GetCombatRatingBonus(20)-- update spell haste
  FaceMelter.hasteDecimal = FaceMelter.spellHaste/100
  local ratingHaste = 1 + FaceMelter.hasteDecimal
  local trueHaste = darknessHaste * shadowformHaste * ratingHaste * FaceMelter.racialHaste

  local name, _, _, _, _, _, _, _, _ = UnitBuff("player", FaceMelter.L["Bloodlust"])
  if name == "Bloodlust" then
    hasteModifierOne = 1.3 * trueHaste
    FaceMelter.hasteModifier = hasteModifierOne
  else
    hasteModifierOne = 1 * trueHaste
    FaceMelter.hasteModifier = hasteModifierOne
  end
  local name, _, _, _, _, _, _, _, _= UnitBuff("player", FaceMelter.L["Heroism"])
  if name == "Heroism" then
    hasteModifierOne = 1.3 * trueHaste
    FaceMelter.hasteModifier = hasteModifierOne
  else
    hasteModifierOne = 1 * trueHaste
    FaceMelter.hasteModifier = hasteModifierOne
  end
  local name, _, _, _, _, _, _, _, _ = UnitBuff("player", FaceMelter.L["Berserking"])
  if name == "Berserking" then
    hasteModifierOne = 1.2 * trueHaste
    FaceMelter.hasteModifier = hasteModifierOne
  else
    hasteModifierOne = 1 * trueHaste
    FaceMelter.hasteModifier = hasteModifierOne
  end
  local name, _, _, _, _, _, _, _, _= UnitBuff("player", FaceMelter.L["Time Warp"])
  if name == "Time Warp" then
    hasteModifierOne = 1.3 * trueHaste
    FaceMelter.hasteModifier = hasteModifierOne
  else
    hasteModifierOne = 1 * trueHaste
    FaceMelter.hasteModifier = hasteModifierOne
  end
  local name, _, _, _, _, _, _, _, _= UnitBuff("player", FaceMelter.L["Dark Intent"])
  if name == "Dark Intent" then
    hasteModifierOne = 1.03 * trueHaste
    FaceMelter.hasteModifier = hasteModifierOne
  else
    hasteModifierOne = 1 * trueHaste
    FaceMelter.hasteModifier = hasteModifierOne
  end

  FaceMelter.trueHaste = FaceMelter.hasteModifier
end

function FaceMelter:CheckStuff()
  local GCD = 1.5/(1 +(FaceMelter.trueHaste/100))
  if GCD < 1 then
      GCD = 1
  end
  local painDuration = 18 
  FaceMelter.vamptouchcasttimer = 1.5/FaceMelter.trueHaste
  local vamptouchDurationb = 15
  local devouringDuration = 24
  local flayBaseTimer = 3
  local flayTenModifier = .51
  local nameTalent, _, _, _, currentRank, _, _, _ = GetTalentInfo(3, 5)
  local blastCooldown = 8 - (currentRank * .5)
  local name, _, _, _, _, _, _, _, _= UnitBuff("player", FaceMelter.L["Vampiric Embrace"])
  if name == "Vampiric Embrace" then
    FaceMelter.hasVE = 1
  else
    FaceMelter.hasVE = ""
  end

  local name, _, _, _, _, _, _, _, _= UnitBuff("player", FaceMelter.L["Shadowform"])
  if name == "Shadowform" then
    FaceMelter.hasFORM = 1
  else
    FaceMelter.hasFORM = ""
  end

  local name, _, _, _, _, _, _, _, _= UnitBuff("player", FaceMelter.L["Inner Fire"])
  if name == "Inner Fire" then
    FaceMelter.hasIF = 1
  else
    FaceMelter.hasIF = ""
  end

  local name, _, _, _, _, _, _, _, _= UnitBuff("player", FaceMelter.L["Inner Will"])
  if name == "Inner Will" then
    FaceMelter.hasIW = 1
  else
    FaceMelter.hasIW = ""
  end

  local name, _, _, decount, _, _, _, _, _= UnitBuff("player", FaceMelter.L["Dark Evangelism"])
  if name == "Dark Evangelism" then
    FaceMelter.DECount = decount
  else
    FaceMelter.DECount = 0
  end

  local name, _, _, count, _, duration, _, _, _= UnitBuff("player", "Shadow Orb")
  if name == "Shadow Orb" then
    FaceMelter.OrbCount = count
  else
    FaceMelter.OrbCount = 0
  end

-- Tier 10 support  
  local tierTenCount = 0
  local tierTenArray = {
    ["HeadSlot"] = "Crimson Acolyte Cowl",
    ["ShoulderSlot"] = "Crimson Acolyte Mantle",
    ["ChestSlot"] = "Crimson Acolyte Raiments",
    ["HandsSlot"] = "Crimson Acolyte Handwraps",
    ["LegsSlot"] = "Crimson Acolyte Pants",
    }
    local sanctifiedTierTenArray = {
    ["HeadSlot"] = "Sanctified Crimson Acolyte Cowl",
    ["ShoulderSlot"] = "Sanctified Crimson Acolyte Mantle",
    ["ChestSlot"] = "Sanctified Crimson Acolyte Raiments",
    ["HandsSlot"] = "Sanctified Crimson Acolyte Handwraps",
    ["LegsSlot"] = "Sanctified Crimson Acolyte Pants",
    }
  for item, name in pairs(tierTenArray) do
    local link = GetInventoryItemLink("player",GetInventorySlotInfo(item))
    if link then
      local foundName = GetItemInfo(link)
      if foundName ~= nil and strfind(foundName, name) then
        tierTenCount = tierTenCount + 1
      end
    end
  end
  for item, name in pairs(sanctifiedTierTenArray) do
    local link = GetInventoryItemLink("player",GetInventorySlotInfo(item))
    if link then
      local foundName = GetItemInfo(link)
      if foundName ~= nil and strfind(foundName, name) then
        tierTenCount = tierTenCount + 1
      end
    end
  end
  if tierTenCount >= 4 then
    flayModifiedTime = flayBaseTimer - flayTenModifier
  elseif tierTenCount < 4 then
    flayModifiedTime = flayBaseTimer
  end 
    flayTimed = flayModifiedTime/FaceMelter.trueHaste
-- Final Gear Adjustments
  if touchTimed == nil then
     FaceMelter.touchTimer = 0
  else 
     FaceMelter.touchTimer = touchTimed
  end
  FaceMelter.blastCooldown = blastCooldown

-- DoT Tolerance calulation
  local DotTolerance = facemelterdb.dotTolerance/100

-- Check remaining DoT durations
-- VARS: name, rank, icon, count, debuffType, duration, expirationTime, unitCaster, isStealable, shouldConsolidate, spellId
  local NowTime = GetTime()
  local guid = UnitGUID("target")
  if guid == nil then guid = 0 end
  local _, _, _, _, _, duration, SWPexpire, _, _, _, _ = UnitAura("target", "Shadow Word: Pain", nil, "PLAYER|HARMFUL")
  if SWPexpire ~= nil then 
    local pHaste = FaceMelter.trueHaste
    if FaceMelter.painHaste[guid] then
      pHaste = FaceMelter.painHaste[guid]
    end
--    local painTick = (1.5 + (1.5 * DotTolerance))/(1 +(FaceMelter.painHaste[guid]/100))
    local painTick = (1.5 + (1.5 * DotTolerance))/(1 +(pHaste/100))
--    FaceMelter.painInterval[guid] = 3/(1+FaceMelter.painHaste[guid]/100)
    FaceMelter.painInterval[guid] = 3/(1+pHaste/100)
    FaceMelter.painRemaining = SWPexpire - NowTime - painTick
    FaceMelter.painList[guid] = SWPexpire - duration
  else
    FaceMelter.painRemaining = 0
    FaceMelter.painHaste[guid] = 0
    FaceMelter.painInterval[guid] = 0
  end
  local _, _, _, _, _, duration, DPexpire, _, _, _, _ = UnitAura("target", "Devouring Plague", nil, "PLAYER|HARMFUL")
  if DPexpire ~= nil then 
    local dHaste = FaceMelter.trueHaste
    if FaceMelter.devouringHaste[guid] then
      dHaste = FaceMelter.devouringHaste[guid]
    end
--    local devouringTick = (1.5 + (1.5 * DotTolerance))/(1 +(FaceMelter.devouringHaste[guid]/100))
    local devouringTick = (1.5 + (1.5 * DotTolerance))/(1 +(dHaste/100))
--    FaceMelter.devouringInterval[guid] = 3/(1+FaceMelter.devouringHaste[guid]/100)
    FaceMelter.devouringInterval[guid] = 3/(1+dHaste/100)
    FaceMelter.devouringRemaining = DPexpire - NowTime - devouringTick
    FaceMelter.devouringList[guid] = DPexpire - duration
  else
    FaceMelter.devouringRemaining = 0
    FaceMelter.devouringHaste[guid] = 0
    FaceMelter.devouringInterval[guid] = 0
  end
  local _, _, _, _, _, duration, VTexpire, _, _, _, _ = UnitAura("target", "Vampiric Touch", nil, "PLAYER|HARMFUL")
  if VTexpire ~= nil then
    local tHaste = FaceMelter.trueHaste
    if FaceMelter.touchHaste[guid] then
      tHaste = FaceMelter.touchHaste[guid]
    end
--    local touchTick = (1.5 + (1.5 * DotTolerance))/(1 +(FaceMelter.touchHaste[guid]/100))
    local touchTick = (1.5 + (1.5 * DotTolerance))/(1 +(tHaste/100))
--    FaceMelter.touchInterval[guid] = 3/(1+FaceMelter.touchHaste[guid]/100)
    FaceMelter.touchInterval[guid] = 3/(1+tHaste/100)
    FaceMelter.touchRemaining = VTexpire - NowTime - touchTick
    FaceMelter.touchList[guid] = VTexpire - duration
  else
    FaceMelter.touchRemaining = 0
    FaceMelter.touchHaste[guid] = 0
    FaceMelter.touchInterval[guid] = 0
  end

-- Toggle IF/IW texture in Suggester frame
  if facemelterdb.useIW then
    FaceMelter.textureList["IF"] = GetSpellTexture("Inner Will")
  else
    FaceMelter.textureList["IF"] = GetSpellTexture("Inner Fire")
  end

  FaceMelter.flayCastTime = flayTimed

  local name, _, _, _, _, _, ESexpire, _, _= UnitBuff("player", "Empowered Shadow")
  if name == "Empowered Shadow" then
    FaceMelter.EmpoweredDuration = ESexpire - NowTime
  else
    FaceMelter.EmpoweredDuration = 0
  end
  
end

-- Options Panel
function FaceMelter:GetMB() 
  return facemelterdb.useMB
end

function FaceMelter:ToggleMB()
  if facemelterdb.useMB then
    facemelterdb.useMB = false
	FaceMelter.MBCheck:SetChecked(false)
	FaceMelter.MBCheck2:SetChecked(false)	
  else
    facemelterdb.useMB = true
	FaceMelter.MBCheck:SetChecked(true)
	FaceMelter.MBCheck2:SetChecked(true)
  end
end

function FaceMelter:GetDeath() 
  return facemelterdb.useDeath
end

function FaceMelter:ToggleDeath()
  if facemelterdb.useDeath then
    facemelterdb.useDeath = false
	FaceMelter.SWDCheck:SetChecked(false)
	FaceMelter.SWDCheck2:SetChecked(false)
  else
    facemelterdb.useDeath = true
	FaceMelter.SWDCheck:SetChecked(true)
	FaceMelter.SWDCheck2:SetChecked(true)
  end
end

function FaceMelter:GetMS() 
  return facemelterdb.useMS
end

function FaceMelter:ToggleMS()
  if facemelterdb.useMS then
    facemelterdb.useMS = false
	FaceMelter.MSCheck:SetChecked(false)
	FaceMelter.MSCheck2:SetChecked(false)	
  else
    facemelterdb.useMS = true
	FaceMelter.MSCheck:SetChecked(true)
	FaceMelter.MSCheck2:SetChecked(true)
  end
end

function FaceMelter:GetFORM() 
  return facemelterdb.useFORM
end

function FaceMelter:ToggleFORM()
  if facemelterdb.useFORM then
    facemelterdb.useFORM = false
	FaceMelter.FORMCheck2:SetChecked(false)	
  else
    facemelterdb.useFORM = true
	FaceMelter.FORMCheck2:SetChecked(true)
  end
end

function FaceMelter:GetFIEND() 
  return facemelterdb.useFIEND
end

function FaceMelter:ToggleFIEND()
  if facemelterdb.useFIEND then
    facemelterdb.useFIEND = false
	FaceMelter.FIENDCheck:SetChecked(false)
	FaceMelter.FIENDCheck2:SetChecked(false)	
  else
    facemelterdb.useFIEND = true
	FaceMelter.FIENDCheck:SetChecked(true)
	FaceMelter.FIENDCheck2:SetChecked(true)
  end
end

function FaceMelter:GetVE() 
  return facemelterdb.useVE
end

function FaceMelter:ToggleVE()
  if facemelterdb.useVE then
    facemelterdb.useVE = false
	FaceMelter.VECheck2:SetChecked(false)	
  else
    facemelterdb.useVE = true
	FaceMelter.VECheck2:SetChecked(true)
  end
end

function FaceMelter:GetDA() 
  return facemelterdb.useDA
end

function FaceMelter:ToggleDA()
  if facemelterdb.useDA then
    facemelterdb.useDA = false
	FaceMelter.DACheck:SetChecked(false)
	FaceMelter.DACheck2:SetChecked(false)	
  else
    facemelterdb.useDA = true
	FaceMelter.DACheck:SetChecked(true)
	FaceMelter.DACheck2:SetChecked(true)
  end
end

function FaceMelter:GetDispersion() 
  return facemelterdb.useDISP
end

function FaceMelter:ToggleDispersion()
  if facemelterdb.useDISP then
    facemelterdb.useDISP = false
	FaceMelter.DISPCheck:SetChecked(false)
	FaceMelter.DISPCheck2:SetChecked(false)
  else
    facemelterdb.useDISP = true
	FaceMelter.DISPCheck:SetChecked(true)
	FaceMelter.DISPCheck2:SetChecked(true)
  end
end

function FaceMelter:GetIF() 
  return facemelterdb.useIF
end

function FaceMelter:ToggleIF()
  if facemelterdb.useIF then
    facemelterdb.useIF = false
	FaceMelter.IFCheck:SetChecked(false)
	FaceMelter.IFCheck2:SetChecked(false)
  else
    facemelterdb.useIF = true
	FaceMelter.IFCheck:SetChecked(true)
	FaceMelter.IFCheck2:SetChecked(true)
    facemelterdb.useIW = false
	FaceMelter.IWCheck:SetChecked(false)
	FaceMelter.IWCheck2:SetChecked(false)
  end
end

function FaceMelter:GetIW() 
  return facemelterdb.useIW
end

function FaceMelter:ToggleIW()
  if facemelterdb.useIW then
    facemelterdb.useIW = false
	FaceMelter.IWCheck:SetChecked(false)
	FaceMelter.IWCheck2:SetChecked(false)
  else
    facemelterdb.useIW = true
	FaceMelter.IWCheck:SetChecked(true)
	FaceMelter.IWCheck2:SetChecked(true)
    facemelterdb.useIF = false
	FaceMelter.IFCheck:SetChecked(false)
	FaceMelter.IFCheck2:SetChecked(false)
  end
end

function FaceMelter:GetButtons()
  return facemelterdb.hideButtons
end

function FaceMelter:ToggleButtons()
  if facemelterdb.hideButtons then
    facemelterdb.hideButtons = false
    FaceMelter.ButtonCheck:SetChecked(false)
  else
    facemelterdb.hideButtons = true
    FaceMelter.ButtonCheck:SetChecked(true)
  end
  FaceMelter:EvalGUIShowHide()
end

function FaceMelter:GetSuggester()
  return facemelterdb.hideSuggester
end

function FaceMelter:ToggleSuggester()
  if facemelterdb.hideSuggester then
    facemelterdb.hideSuggester = false
    FaceMelter.UICheck:SetChecked(false)
  else
    facemelterdb.hideSuggester = true
    FaceMelter.UICheck:SetChecked(true)
  end
  FaceMelter:EvalGUIShowHide()
end

function FaceMelter:EvalGUIShowHide()
  if facemelterdb.truehide then
    FaceMelter.displayFrame_options:Hide()
    FaceMelter.displayFrame:Hide()
  elseif facemelterdb.hideSuggester then
    FaceMelter.displayFrame_options:Hide()
    FaceMelter.displayFrame:Hide()
  else
    FaceMelter.displayFrame:Show()
    if not facemelterdb.hideButtons then
      FaceMelter.displayFrame_options:Show()
    else
      FaceMelter.displayFrame_options:Hide()
    end
    FaceMelter.textureList["VT"] = GetSpellTexture("Vampiric Touch")
    FaceMelter.textureList["SWP"] = GetSpellTexture("Shadow Word: Pain")
    FaceMelter.textureList["MB"] = GetSpellTexture("Mind Blast")
    FaceMelter.textureList["SWD"] = GetSpellTexture("Shadow Word: Death")
    FaceMelter.textureList["FORM"] = GetSpellTexture("Shadowform")
    FaceMelter.textureList["FIEND"] = GetSpellTexture("Shadowfiend")
    FaceMelter.textureList["MF"] = GetSpellTexture("Mind Flay")
    FaceMelter.textureList["MS"] = GetSpellTexture("Mind Spike")
    FaceMelter.textureList["VE"] = GetSpellTexture("Vampiric Embrace")
    FaceMelter.textureList["DP"] = GetSpellTexture("Devouring Plague")
    FaceMelter.textureList["DA"] = GetSpellTexture("Archangel")
    FaceMelter.textureList["IF"] = GetSpellTexture("Inner Fire")
    FaceMelter.textureList["IW"] = GetSpellTexture("Inner Will")
    FaceMelter.textureList["DISP"] = GetSpellTexture("Dispersion")
  end
end

function FaceMelter:DetermineTrueShowHide()
  local nameTalent, _, _, _, hasShadowform, _, _, _ = GetTalentInfo(3, 8)
  if facemelterdb.hideSuggester == true then
    facemelterdb.truehide = true
  elseif hasShadowform < 1 or hasShadowform == nil then
	facemelterdb.truehide = true    
  else
    facemelterdb.truehide = false
  end
end

function FaceMelter:GetPri(spell)
  return facemelterdb.priRev[spell]
end

function FaceMelter:SetPri(spell, pri)
  local oldPri = facemelterdb.priRev[spell]
  local oldSpell = facemelterdb.pri[pri]  
  facemelterdb.priRev[spell] = pri
  facemelterdb.priRev[oldSpell] = oldPri
  facemelterdb.pri[oldPri] = oldSpell
  facemelterdb.pri[pri] = spell
  _G["FaceMelterOptions_sl_" .. oldSpell]:SetValue(oldPri)
  _G["FaceMelterOptions_sl_" .. oldSpell .. "Text"]:SetText(oldPri)
end

function FaceMelter:GetLocked() 
  return facemelterdb.locked
end

function FaceMelter:ToggleLocked()
  if facemelterdb.locked then
    facemelterdb.locked = false
    FaceMelter.displayFrame:SetScript("OnMouseDown", function(self) self:StartMoving() end)
    FaceMelter.displayFrame:SetScript("OnMouseUp", function(self) self:StopMovingOrSizing() end)
    FaceMelter.displayFrame:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
    FaceMelter.displayFrame:SetBackdropColor(0, 0, 0, .4)
	FaceMelter.displayFrame:EnableMouse(true)
	FaceMelter.LockCheck:SetChecked(false)
  else
    facemelterdb.locked = true
    FaceMelter.displayFrame:SetScript("OnMouseDown", nil)
    FaceMelter.displayFrame:SetScript("OnMouseUp", nil)
    FaceMelter.displayFrame:SetScript("OnDragStop", nil)
    FaceMelter.displayFrame:SetBackdropColor(0, 0, 0, 0)
	FaceMelter.displayFrame:EnableMouse(false)
	FaceMelter.LockCheck:SetChecked(true)
  end
end

function FaceMelter:GetScale()
  return facemelterdb.scale
end

function FaceMelter:SetScale(num)
  facemelterdb.scale = num
  FaceMelter.displayFrame:SetScale(facemelterdb.scale)
  FaceMelter.cooldownFrame:SetScale(facemelterdb.scale)
end

function FaceMelter:GetHealthPercent()
  return facemelterdb.healthPercent
end

function FaceMelter:SetHealthPercent(num)
  facemelterdb.healthPercent = num
end

function FaceMelter:GetExecuteHealth()
  return facemelterdb.executeHealth
end

function FaceMelter:SetExecuteHealth(num)
  facemelterdb.executeHealth = num
end

function FaceMelter:GetDeathMana()
  return facemelterdb.deathMana
end

function FaceMelter:SetDeathMana(num)
  facemelterdb.deathMana = num
end

function FaceMelter:GetDispersionMana()
  return facemelterdb.dispersionMana
end

function FaceMelter:SetDispersionMana(num)
  facemelterdb.dispersionMana = num
end

function FaceMelter:GetDotTolerance()
  return facemelterdb.dotTolerance
end

function FaceMelter:SetDotTolerance(num)
  facemelterdb.dotTolerance = num
end

function FaceMelter:GetEmpoweredRemaining()
  return facemelterdb.empoweredRemaining
end

function FaceMelter:SetEmpoweredRemaining(num)
  facemelterdb.empoweredRemaining = num
end

function FaceMelter:GetMinOrbs()
  return facemelterdb.minOrbs
end

function FaceMelter:SetMinOrbs(num)
  facemelterdb.minOrbs = num
end


function FaceMelter:SetMiniAlpha(num)
	facemelterdb.miniOptionsAlpha = num
	FaceMelter.displayFrame_options:SetAlpha(num)
	if num == 0 then
		FaceMelter.displayFrame_options:Hide()
	else
		FaceMelter.displayFrame_options:Show()
	end
end

function FaceMelter:CreateOptionFrame()

--Create Main Options Pane
  FaceMelter.panel = CreateFrame("Frame", "FaceMelterOptions", UIParent);
  FaceMelter.panel.name = "FaceMelter Reloaded";

  local fstringMain1 = FaceMelter.panel:CreateFontString("FaceMelterOptions_string1","OVERLAY","GameFontNormal")
  fstringMain1:SetText("GUI Options/Settings")
  fstringMain1:SetPoint("TOPLEFT", 10, -10)

  local fstringMain2 = FaceMelter.panel:CreateFontString("FaceMelterOptions_string1","OVERLAY","GameFontNormal")
  fstringMain2:SetText("GUI Lock/Scaling")
  fstringMain2:SetPoint("TOPLEFT", 10, -36)

  local checkboxMain2 = CreateFrame("CheckButton", "$parent_cb1", FaceMelter.panel, "UICheckButtonTemplate")
  checkboxMain2:SetWidth(18)
  checkboxMain2:SetHeight(18)
  checkboxMain2:SetScript("OnClick", function() FaceMelter:ToggleLocked() end)
  checkboxMain2:SetPoint("TOPLEFT", 150, -36)
  checkboxMain2:SetChecked(FaceMelter:GetLocked())
  FaceMelter.LockCheck = checkboxMain2

  local sliderMain2 = CreateFrame("Slider", "$parent_sl2", FaceMelter.panel, "OptionsSliderTemplate")
  sliderMain2:SetMinMaxValues(.5, 1.5)
  sliderMain2:SetHeight(14)
  sliderMain2:SetValue(FaceMelter:GetScale())
  sliderMain2:SetValueStep(.05)
  sliderMain2:SetScript("OnValueChanged", function(self) FaceMelter:SetScale(self:GetValue()); _G[self:GetName() .. "Text"]:SetText(self:GetValue())  end)
  _G[sliderMain2:GetName() .. "Low"]:SetText("0.5")
  _G[sliderMain2:GetName() .. "High"]:SetText("1.5")
  _G[sliderMain2:GetName() .. "Text"]:SetText(FaceMelter:GetScale())
  sliderMain2:SetPoint("TOPRIGHT", -10, -36)

  local fstringMain3 = FaceMelter.panel:CreateFontString("FaceMelterOptions_stringMO","OVERLAY","GameFontNormal")
  fstringMain3:SetText("GUI Checkbox Alpha")
  fstringMain3:SetPoint("TOPLEFT", 10, -62)
  
  local sliderMain3 = CreateFrame("Slider", "$parent_sMO", FaceMelter.panel, "OptionsSliderTemplate")
  sliderMain3:SetMinMaxValues(0, 1)
  sliderMain3:SetValue(facemelterdb.miniOptionsAlpha)
  sliderMain3:SetHeight(14)
  sliderMain3:SetValueStep(.05)
  sliderMain3:SetScript("OnValueChanged", function(self) FaceMelter:SetMiniAlpha(self:GetValue()); _G[self:GetName() .. "Text"]:SetText(self:GetValue()) end)
  _G[sliderMain3:GetName() .. "Low"]:SetText("0")
  _G[sliderMain3:GetName() .. "High"]:SetText("1")
  _G[sliderMain3:GetName() .. "Text"]:SetText(facemelterdb.miniOptionsAlpha)
  sliderMain3:SetPoint("TOPRIGHT", -10, -62)

  local fstringMain4 = FaceMelter.panel:CreateFontString("FaceMelterOptions_string1","OVERLAY","GameFontNormal")
  fstringMain4:SetText("Disable Checkboxes on Suggester Frame")
  fstringMain4:SetPoint("TOPLEFT", 10, -88)

  local checkboxMain4 = CreateFrame("CheckButton", "$parent_cb1", FaceMelter.panel, "UICheckButtonTemplate")
  checkboxMain4:SetWidth(18)
  checkboxMain4:SetHeight(18)
  checkboxMain4:SetScript("OnClick", function() FaceMelter:ToggleButtons() end)
  checkboxMain4:SetPoint("TOPLEFT", 260, -88)
  checkboxMain4:SetChecked(FaceMelter:GetButtons())
  FaceMelter.ButtonCheck = checkboxMain4
  
  local fstringMain5 = FaceMelter.panel:CreateFontString("FaceMelterOptions_string1","OVERLAY","GameFontNormal")
  fstringMain5:SetText("Disable Suggester Frame")
  fstringMain5:SetPoint("TOPLEFT", 10, -114)

  local checkboxMain5 = CreateFrame("CheckButton", "$parent_cb1", FaceMelter.panel, "UICheckButtonTemplate")
  checkboxMain5:SetWidth(18)
  checkboxMain5:SetHeight(18)
  checkboxMain5:SetScript("OnClick", function() FaceMelter:ToggleSuggester() end)
  checkboxMain5:SetPoint("TOPLEFT", 260, -114)
  checkboxMain5:SetChecked(FaceMelter:GetSuggester())
  FaceMelter.UICheck = checkboxMain5

  InterfaceOptions_AddCategory(FaceMelter.panel);

--Create Priority Options Pane
  FaceMelter.priorityPanel = CreateFrame("Frame", "FaceMelterPriorities", FaceMelter.panel);
  FaceMelter.priorityPanel.name = "Priorities";
  FaceMelter.priorityPanel.parent = FaceMelter.panel.name;

  local fstringPri1 = FaceMelter.priorityPanel:CreateFontString("FaceMelterOptions_string6a","OVERLAY","GameFontNormal")
  fstringPri1:SetText("Spell Priority (1 is first). Uncheck spells to remove from rotation")
  fstringPri1:SetPoint("TOPLEFT", 10, -10)

  local fstringPri2 = FaceMelter.priorityPanel:CreateFontString("FaceMelterOptions_string6a","OVERLAY","GameFontNormal")
  fstringPri2:SetText("Buff Spells")
  fstringPri2:SetPoint("TOPLEFT", 10, -36)

  local fstringPri3 = FaceMelter.priorityPanel:CreateFontString("FaceMelterOptions_string1","OVERLAY","GameFontNormal")
  fstringPri3:SetText("Shadowform")
  fstringPri3:SetPoint("TOPLEFT", 10, -62)

  local checkboxPri3 = CreateFrame("CheckButton", "$parent_cb5", FaceMelter.priorityPanel, "UICheckButtonTemplate")
  checkboxPri3:SetWidth(18)
  checkboxPri3:SetHeight(18)
  checkboxPri3:SetScript("OnClick", function() FaceMelter:ToggleFORM() end)
  checkboxPri3:SetPoint("TOPLEFT", 150, -62)
  checkboxPri3:SetChecked(FaceMelter:GetFORM())
  FaceMelter.FORMCheck2 = checkboxPri3

  local sliderPri3 = CreateFrame("Slider", "FaceMelterOptions_sl_FORM", FaceMelter.priorityPanel, "OptionsSliderTemplate")
  sliderPri3:SetHeight(14)
  sliderPri3:SetMinMaxValues(1, 12)
  sliderPri3:SetValueStep(1)
  sliderPri3:SetValue(FaceMelter:GetPri("FORM"))
  _G[sliderPri3:GetName() .. "Low"]:SetText("1")
  _G[sliderPri3:GetName() .. "High"]:SetText("12")
  _G[sliderPri3:GetName() .. "Text"]:SetText(FaceMelter:GetPri("FORM"))
  sliderPri3:SetPoint("TOPRIGHT", -10, -62)
  sliderPri3:SetScript("OnValueChanged", function(self) FaceMelter:SetPri("FORM", self:GetValue()); _G[self:GetName() .. "Text"]:SetText(self:GetValue()) end)

  local fstringPri4 = FaceMelter.priorityPanel:CreateFontString("FaceMelterOptions_string1","OVERLAY","GameFontNormal")
  fstringPri4:SetText("Vampiric Embrace")
  fstringPri4:SetPoint("TOPLEFT", 10, -88)

  local checkboxPri4 = CreateFrame("CheckButton", "$parent_cb6", FaceMelter.priorityPanel, "UICheckButtonTemplate")
  checkboxPri4:SetWidth(18)
  checkboxPri4:SetHeight(18)
  checkboxPri4:SetScript("OnClick", function() FaceMelter:ToggleVE() end)
  checkboxPri4:SetPoint("TOPLEFT", 150, -88)
  checkboxPri4:SetChecked(FaceMelter:GetVE())
  FaceMelter.VECheck2 = checkboxPri4

  local sliderPri4 = CreateFrame("Slider", "FaceMelterOptions_sl_VE", FaceMelter.priorityPanel, "OptionsSliderTemplate")
  sliderPri4:SetHeight(14)
  sliderPri4:SetMinMaxValues(1, 12)
  sliderPri4:SetValueStep(1)
  sliderPri4:SetValue(FaceMelter:GetPri("VE"))
  _G[sliderPri4:GetName() .. "Low"]:SetText("1")
  _G[sliderPri4:GetName() .. "High"]:SetText("12")
  _G[sliderPri4:GetName() .. "Text"]:SetText(FaceMelter:GetPri("VE"))
  sliderPri4:SetPoint("TOPRIGHT", -10, -88)
  sliderPri4:SetScript("OnValueChanged", function(self) FaceMelter:SetPri("VE", self:GetValue()); _G[self:GetName() .. "Text"]:SetText(self:GetValue()) end)

  local fstringPri5 = FaceMelter.priorityPanel:CreateFontString("FaceMelterOptions_string6a","OVERLAY","GameFontNormal")
  fstringPri5:SetText("Inner Fire")
  fstringPri5:SetPoint("TOPLEFT", 10, -114)

  local checkboxPri5 = CreateFrame("CheckButton", "$parent_cb6", FaceMelter.priorityPanel, "UICheckButtonTemplate")
  checkboxPri5:SetWidth(18)
  checkboxPri5:SetHeight(18)
  checkboxPri5:SetScript("OnClick", function() FaceMelter:ToggleIF() end)
  checkboxPri5:SetPoint("TOPLEFT", 70, -114)
  checkboxPri5:SetChecked(FaceMelter:GetIF())
  FaceMelter.IFCheck2 = checkboxPri5

  local fstringPri5a = FaceMelter.priorityPanel:CreateFontString("FaceMelterOptions_string6a","OVERLAY","GameFontNormal")
  fstringPri5a:SetText("Inner Will")
  fstringPri5a:SetPoint("TOPLEFT", 130, -114)

  local checkboxPri5a = CreateFrame("CheckButton", "$parent_cb6", FaceMelter.priorityPanel, "UICheckButtonTemplate")
  checkboxPri5a:SetWidth(18)
  checkboxPri5a:SetHeight(18)
  checkboxPri5a:SetScript("OnClick", function() FaceMelter:ToggleIW() end)
  checkboxPri5a:SetPoint("TOPLEFT", 190, -114)
  checkboxPri5a:SetChecked(FaceMelter:GetIW())
  FaceMelter.IWCheck2 = checkboxPri5a

  local sliderPri5 = CreateFrame("Slider", "FaceMelterOptions_sl_IF", FaceMelter.priorityPanel, "OptionsSliderTemplate")
  sliderPri5:SetHeight(14)
  sliderPri5:SetMinMaxValues(1, 12)
  sliderPri5:SetValueStep(1)
  sliderPri5:SetValue(FaceMelter:GetPri("IF"))
  _G[sliderPri5:GetName() .. "Low"]:SetText("1")
  _G[sliderPri5:GetName() .. "High"]:SetText("12")
  _G[sliderPri5:GetName() .. "Text"]:SetText(FaceMelter:GetPri("IF"))
  sliderPri5:SetPoint("TOPRIGHT", -10, -114)
  sliderPri5:SetScript("OnValueChanged", function(self) FaceMelter:SetPri("IF", self:GetValue()); _G[self:GetName() .. "Text"]:SetText(self:GetValue()) end)

  local fstringPri6 = FaceMelter.priorityPanel:CreateFontString("FaceMelterOptions_string6a","OVERLAY","GameFontNormal")
  fstringPri6:SetText("Damage over Time Spells")
  fstringPri6:SetPoint("TOPLEFT", 10, -140)

  local fstringPri7 = FaceMelter.priorityPanel:CreateFontString("FaceMelterOptions_string7","OVERLAY","GameFontNormal")
  fstringPri7:SetText("Vampiric Touch")
  fstringPri7:SetPoint("TOPLEFT", 10, -166)

  local sliderPri7 = CreateFrame("Slider", "FaceMelterOptions_sl_VT", FaceMelter.priorityPanel, "OptionsSliderTemplate")
  sliderPri7:SetHeight(14)
  sliderPri7:SetMinMaxValues(1, 12)
  sliderPri7:SetValueStep(1)
  sliderPri7:SetValue(FaceMelter:GetPri("VT"))
  _G[sliderPri7:GetName() .. "Low"]:SetText("1")
  _G[sliderPri7:GetName() .. "High"]:SetText("12")
  _G[sliderPri7:GetName() .. "Text"]:SetText(FaceMelter:GetPri("VT"))
  sliderPri7:SetPoint("TOPRIGHT", -10, -166)
  sliderPri7:SetScript("OnValueChanged", function(self) FaceMelter:SetPri("VT", self:GetValue()); _G[self:GetName() .. "Text"]:SetText(self:GetValue()) end)

  local fstringPri8 = FaceMelter.priorityPanel:CreateFontString("FaceMelterOptions_string6a","OVERLAY","GameFontNormal")
  fstringPri8:SetText("Devouring Plague")
  fstringPri8:SetPoint("TOPLEFT", 10, -192)

  local sliderPri8 = CreateFrame("Slider", "FaceMelterOptions_sl_DP", FaceMelter.priorityPanel, "OptionsSliderTemplate")
  sliderPri8:SetHeight(14)
  sliderPri8:SetMinMaxValues(1, 12)
  sliderPri8:SetValueStep(1)
  sliderPri8:SetValue(FaceMelter:GetPri("DP"))
  _G[sliderPri8:GetName() .. "Low"]:SetText("1")
  _G[sliderPri8:GetName() .. "High"]:SetText("12")
  _G[sliderPri8:GetName() .. "Text"]:SetText(FaceMelter:GetPri("DP"))
  sliderPri8:SetPoint("TOPRIGHT", -10, -192)
  sliderPri8:SetScript("OnValueChanged", function(self) FaceMelter:SetPri("DP", self:GetValue()); _G[self:GetName() .. "Text"]:SetText(self:GetValue()) end)

  local fstringPri9 = FaceMelter.priorityPanel:CreateFontString("FaceMelterOptions_string6","OVERLAY","GameFontNormal")
  fstringPri9:SetText("SW: Pain")
  fstringPri9:SetPoint("TOPLEFT", 10, -218)

  local sliderPri9 = CreateFrame("Slider", "FaceMelterOptions_sl_SWP", FaceMelter.priorityPanel, "OptionsSliderTemplate")
  sliderPri9:SetHeight(14)
  sliderPri9:SetMinMaxValues(1, 12)
  sliderPri9:SetValueStep(1)
  sliderPri9:SetValue(FaceMelter:GetPri("SWP"))
  _G[sliderPri9:GetName() .. "Low"]:SetText("1")
  _G[sliderPri9:GetName() .. "High"]:SetText("12")
  _G[sliderPri9:GetName() .. "Text"]:SetText(FaceMelter:GetPri("SWP"))
  sliderPri9:SetPoint("TOPRIGHT", -10, -218)
  sliderPri9:SetScript("OnValueChanged", function(self) FaceMelter:SetPri("SWP", self:GetValue()); _G[self:GetName() .. "Text"]:SetText(self:GetValue()) end)

  local fstringPri10 = FaceMelter.priorityPanel:CreateFontString("FaceMelterOptions_string6a","OVERLAY","GameFontNormal")
  fstringPri10:SetText("Direct Damage and Cooldown Spells")
  fstringPri10:SetPoint("TOPLEFT", 10, -244)

  local fstringPri11 = FaceMelter.priorityPanel:CreateFontString("FaceMelterOptions_string1","OVERLAY","GameFontNormal")
  fstringPri11:SetText("Shadowfiend")
  fstringPri11:SetPoint("TOPLEFT", 10, -270)

  local checkboxPri11 = CreateFrame("CheckButton", "$parent_cb7", FaceMelter.priorityPanel, "UICheckButtonTemplate")
  checkboxPri11:SetWidth(18)
  checkboxPri11:SetHeight(18)
  checkboxPri11:SetScript("OnClick", function() FaceMelter:ToggleFIEND() end)
  checkboxPri11:SetPoint("TOPLEFT", 150, -270)
  checkboxPri11:SetChecked(FaceMelter:GetFIEND())
  FaceMelter.FIENDCheck2 = checkboxPri11

  local sliderPri11 = CreateFrame("Slider", "FaceMelterOptions_sl_FIEND", FaceMelter.priorityPanel, "OptionsSliderTemplate")
  sliderPri11:SetHeight(14)
  sliderPri11:SetMinMaxValues(1, 12)
  sliderPri11:SetValueStep(1)
  sliderPri11:SetValue(FaceMelter:GetPri("FIEND"))
  _G[sliderPri11:GetName() .. "Low"]:SetText("1")
  _G[sliderPri11:GetName() .. "High"]:SetText("12")
  _G[sliderPri11:GetName() .. "Text"]:SetText(FaceMelter:GetPri("FIEND"))
  sliderPri11:SetPoint("TOPRIGHT", -10, -270)
  sliderPri11:SetScript("OnValueChanged", function(self) FaceMelter:SetPri("FIEND", self:GetValue()); _G[self:GetName() .. "Text"]:SetText(self:GetValue()) end)

  local fstringPri12 = FaceMelter.priorityPanel:CreateFontString("FaceMelterOptions_string1","OVERLAY","GameFontNormal")
  fstringPri12:SetText("Dark Archangel")
  fstringPri12:SetPoint("TOPLEFT", 10, -296)

  local checkboxPri12 = CreateFrame("CheckButton", "$parent_cb8", FaceMelter.priorityPanel, "UICheckButtonTemplate")
  checkboxPri12:SetWidth(18)
  checkboxPri12:SetHeight(18)
  checkboxPri12:SetScript("OnClick", function() FaceMelter:ToggleDA() end)
  checkboxPri12:SetPoint("TOPLEFT", 150, -296)
  checkboxPri12:SetChecked(FaceMelter:GetDA())
  FaceMelter.DACheck2 = checkboxPri12

  local sliderPri12 = CreateFrame("Slider", "FaceMelterOptions_sl_DA", FaceMelter.priorityPanel, "OptionsSliderTemplate")
  sliderPri12:SetHeight(14)
  sliderPri12:SetMinMaxValues(1, 12)
  sliderPri12:SetValueStep(1)
  sliderPri12:SetValue(FaceMelter:GetPri("DA"))
  _G[sliderPri12:GetName() .. "Low"]:SetText("1")
  _G[sliderPri12:GetName() .. "High"]:SetText("12")
  _G[sliderPri12:GetName() .. "Text"]:SetText(FaceMelter:GetPri("DA"))
  sliderPri12:SetPoint("TOPRIGHT", -10, -296)
  sliderPri12:SetScript("OnValueChanged", function(self) FaceMelter:SetPri("DA", self:GetValue()); _G[self:GetName() .. "Text"]:SetText(self:GetValue()) end)

  local fstringPri13 = FaceMelter.priorityPanel:CreateFontString("FaceMelterOptions_string1","OVERLAY","GameFontNormal")
  fstringPri13:SetText("Dispersion")
  fstringPri13:SetPoint("TOPLEFT", 10, -322)

  local checkboxPri13 = CreateFrame("CheckButton", "$parent_cb8", FaceMelter.priorityPanel, "UICheckButtonTemplate")
  checkboxPri13:SetWidth(18)
  checkboxPri13:SetHeight(18)
  checkboxPri13:SetScript("OnClick", function() FaceMelter:ToggleDispersion() end)
  checkboxPri13:SetPoint("TOPLEFT", 150, -322)
  checkboxPri13:SetChecked(FaceMelter:GetDispersion())
  FaceMelter.DISPCheck2 = checkboxPri13

  local sliderPri13 = CreateFrame("Slider", "FaceMelterOptions_sl_DISP", FaceMelter.priorityPanel, "OptionsSliderTemplate")
  sliderPri13:SetHeight(14)
  sliderPri13:SetMinMaxValues(1, 12)
  sliderPri13:SetValueStep(1)
  sliderPri13:SetValue(FaceMelter:GetPri("DISP"))
  _G[sliderPri13:GetName() .. "Low"]:SetText("1")
  _G[sliderPri13:GetName() .. "High"]:SetText("12")
  _G[sliderPri13:GetName() .. "Text"]:SetText(FaceMelter:GetPri("DISP"))
  sliderPri13:SetPoint("TOPRIGHT", -10, -322)
  sliderPri13:SetScript("OnValueChanged", function(self) FaceMelter:SetPri("DISP", self:GetValue()); _G[self:GetName() .. "Text"]:SetText(self:GetValue()) end)

  local fstringPri14 = FaceMelter.priorityPanel:CreateFontString("FaceMelterOptions_string8","OVERLAY","GameFontNormal")
  fstringPri14:SetText("Mind Blast")
  fstringPri14:SetPoint("TOPLEFT", 10, -348)

  local checkboxPri14 = CreateFrame("CheckButton", "$parent_cb2", FaceMelter.priorityPanel, "UICheckButtonTemplate")
  checkboxPri14:SetWidth(18)
  checkboxPri14:SetHeight(18)
  checkboxPri14:SetScript("OnClick", function() FaceMelter:ToggleMB() end)
  checkboxPri14:SetPoint("TOPLEFT", 150, -348)
  checkboxPri14:SetChecked(FaceMelter:GetMB())
  FaceMelter.MBCheck2 = checkboxPri14

  local sliderPri14 = CreateFrame("Slider", "FaceMelterOptions_sl_MB", FaceMelter.priorityPanel, "OptionsSliderTemplate")
  sliderPri14:SetHeight(14)
  sliderPri14:SetMinMaxValues(1, 12)
  sliderPri14:SetValueStep(1)
  sliderPri14:SetValue(FaceMelter:GetPri("MB"))
  _G[sliderPri14:GetName() .. "Low"]:SetText("1")
  _G[sliderPri14:GetName() .. "High"]:SetText("12")
  _G[sliderPri14:GetName() .. "Text"]:SetText(FaceMelter:GetPri("MB"))
  sliderPri14:SetPoint("TOPRIGHT", -10, -348)
  sliderPri14:SetScript("OnValueChanged", function(self) FaceMelter:SetPri("MB", self:GetValue()); _G[self:GetName() .. "Text"]:SetText(self:GetValue()) end)

  local fstringPri15 = FaceMelter.priorityPanel:CreateFontString("FaceMelterOptions_string9","OVERLAY","GameFontNormal")
  fstringPri15:SetText("SW: Death")
  fstringPri15:SetPoint("TOPLEFT", 10, -374)

  local checkboxPri15 = CreateFrame("CheckButton", "$parent_cb3", FaceMelter.priorityPanel, "UICheckButtonTemplate")
  checkboxPri15:SetWidth(18)
  checkboxPri15:SetHeight(18)
  checkboxPri15:SetScript("OnClick", function() FaceMelter:ToggleDeath() end)
  checkboxPri15:SetPoint("TOPLEFT", 150, -374)
  checkboxPri15:SetChecked(FaceMelter:GetDeath())
  FaceMelter.SWDCheck2 = checkboxPri15

  local sliderPri15 = CreateFrame("Slider", "FaceMelterOptions_sl_SWD", FaceMelter.priorityPanel, "OptionsSliderTemplate")
  sliderPri15:SetHeight(14)
  sliderPri15:SetMinMaxValues(1, 12)
  sliderPri15:SetValueStep(1)
  sliderPri15:SetValue(FaceMelter:GetPri("SWD"))
  _G[sliderPri15:GetName() .. "Low"]:SetText("1")
  _G[sliderPri15:GetName() .. "High"]:SetText("12")
  _G[sliderPri15:GetName() .. "Text"]:SetText(FaceMelter:GetPri("SWD"))
  sliderPri15:SetPoint("TOPRIGHT", -10, -374)
  sliderPri15:SetScript("OnValueChanged", function(self) FaceMelter:SetPri("SWD", self:GetValue()); _G[self:GetName() .. "Text"]:SetText(self:GetValue()) end)

  local fstringPri16 = FaceMelter.priorityPanel:CreateFontString("FaceMelterOptions_string6a","OVERLAY","GameFontNormal")
  fstringPri16:SetText("Mind Spike")
  fstringPri16:SetPoint("TOPLEFT", 10, -400)

  local checkboxPri16 = CreateFrame("CheckButton", "$parent_cb4", FaceMelter.priorityPanel, "UICheckButtonTemplate")
  checkboxPri16:SetWidth(18)
  checkboxPri16:SetHeight(18)
  checkboxPri16:SetScript("OnClick", function() FaceMelter:ToggleMS() end)
  checkboxPri16:SetPoint("TOPLEFT", 150, -400)
  checkboxPri16:SetChecked(FaceMelter:GetMS())
  FaceMelter.MSCheck2 = checkboxPri16

  local sliderPri16 = CreateFrame("Slider", "FaceMelterOptions_sl_MS", FaceMelter.priorityPanel, "OptionsSliderTemplate")
  sliderPri16:SetHeight(14)
  sliderPri16:SetMinMaxValues(1, 12)
  sliderPri16:SetValueStep(1)
  sliderPri16:SetValue(FaceMelter:GetPri("MS"))
  _G[sliderPri16:GetName() .. "Low"]:SetText("1")
  _G[sliderPri16:GetName() .. "High"]:SetText("12")
  _G[sliderPri16:GetName() .. "Text"]:SetText(FaceMelter:GetPri("MS"))
  sliderPri16:SetPoint("TOPRIGHT", -10, -400)
  sliderPri16:SetScript("OnValueChanged", function(self) FaceMelter:SetPri("MS", self:GetValue()); _G[self:GetName() .. "Text"]:SetText(self:GetValue()) end)

  InterfaceOptions_AddCategory(FaceMelter.priorityPanel); 

--Create Spell Options Pane
  FaceMelter.additionalPanel = CreateFrame("Frame", "FaceMelterAdditional", FaceMelter.panel);
  FaceMelter.additionalPanel.name = "Spell Options";
  FaceMelter.additionalPanel.parent = FaceMelter.panel.name;

  local fstringAdd2 = FaceMelter.additionalPanel:CreateFontString("FaceMelterOptions_string1","OVERLAY","GameFontNormal")
  fstringAdd2:SetText("Additional Conditions for Spell Cast")
  fstringAdd2:SetPoint("TOPLEFT", 10, -10)

  local fstringAdd2 = FaceMelter.additionalPanel:CreateFontString("FaceMelterOptions_string1","OVERLAY","GameFontNormal")
  fstringAdd2:SetText("Minimum Shadow Orbs for MB")
  fstringAdd2:SetPoint("TOPLEFT", 10, -36)

  local sliderAdd2 = CreateFrame("Slider", "FaceMelterOptions_Orb_Count", FaceMelter.additionalPanel, "OptionsSliderTemplate")
  sliderAdd2:SetHeight(14)
  sliderAdd2:SetMinMaxValues(0, 3)
  sliderAdd2:SetValueStep(1)
  sliderAdd2:SetValue(FaceMelter:GetMinOrbs())
  _G[sliderAdd2:GetName() .. "Low"]:SetText("0")
  _G[sliderAdd2:GetName() .. "High"]:SetText("3")
  _G[sliderAdd2:GetName() .. "Text"]:SetText(FaceMelter:GetMinOrbs())
  sliderAdd2:SetPoint("TOPRIGHT", -10, -36)
  sliderAdd2:SetScript("OnValueChanged", function(self) FaceMelter:SetMinOrbs(self:GetValue()); _G[self:GetName() .. "Text"]:SetText(self:GetValue())  end)

  local fstringAdd3 = FaceMelter.additionalPanel:CreateFontString("FaceMelterOptions_string4","OVERLAY","GameFontNormal")
  fstringAdd3:SetText("Health Percent for SW:D Cutoff")
  fstringAdd3:SetPoint("TOPLEFT", 10, -62)

  local sliderAdd3 = CreateFrame("Slider", "FaceMelterOptions_SWD_pHealth", FaceMelter.additionalPanel, "OptionsSliderTemplate")
  sliderAdd3:SetMinMaxValues(0, 100)
  sliderAdd3:SetHeight(14)
  sliderAdd3:SetValue(FaceMelter:GetHealthPercent())
  sliderAdd3:SetValueStep(1)
  sliderAdd3:SetScript("OnValueChanged", function(self) FaceMelter:SetHealthPercent(self:GetValue()); _G[self:GetName() .. "Text"]:SetText(self:GetValue()) end)
  _G[sliderAdd3:GetName() .. "Low"]:SetText("1")
  _G[sliderAdd3:GetName() .. "High"]:SetText("100")
  _G[sliderAdd3:GetName() .. "Text"]:SetText(FaceMelter:GetHealthPercent())
  sliderAdd3:SetPoint("TOPRIGHT", -10, -62)

  local fstringAdd4 = FaceMelter.additionalPanel:CreateFontString("FaceMelterOptions_string4","OVERLAY","GameFontNormal")
  fstringAdd4:SetText("Target Health to use SW:D(Execute Phase)")
  fstringAdd4:SetPoint("TOPLEFT", 10, -88)

  local sliderAdd4 = CreateFrame("Slider", "FaceMelterOptions_SWD_execute", FaceMelter.additionalPanel, "OptionsSliderTemplate")
  sliderAdd4:SetMinMaxValues(0, 100)
  sliderAdd4:SetHeight(14)
  sliderAdd4:SetValue(FaceMelter:GetExecuteHealth())
  sliderAdd4:SetValueStep(1)
  sliderAdd4:SetScript("OnValueChanged", function(self) FaceMelter:SetExecuteHealth(self:GetValue()); _G[self:GetName() .. "Text"]:SetText(self:GetValue()) end)
  _G[sliderAdd4:GetName() .. "Low"]:SetText("1")
  _G[sliderAdd4:GetName() .. "High"]:SetText("100")
  _G[sliderAdd4:GetName() .. "Text"]:SetText(FaceMelter:GetExecuteHealth())
  sliderAdd4:SetPoint("TOPRIGHT", -10, -88)

  local fstringAdd5 = FaceMelter.additionalPanel:CreateFontString("FaceMelterOptions_string4","OVERLAY","GameFontNormal")
  fstringAdd5:SetText("Player Mana to use SW:D")
  fstringAdd5:SetPoint("TOPLEFT", 10, -114)

  local sliderAdd5 = CreateFrame("Slider", "FaceMelterOptions_SWD_mana", FaceMelter.additionalPanel, "OptionsSliderTemplate")
  sliderAdd5:SetMinMaxValues(0, 100)
  sliderAdd5:SetHeight(14)
  sliderAdd5:SetValue(FaceMelter:GetDeathMana())
  sliderAdd5:SetValueStep(1)
  sliderAdd5:SetScript("OnValueChanged", function(self) FaceMelter:SetDeathMana(self:GetValue()); _G[self:GetName() .. "Text"]:SetText(self:GetValue()) end)
  _G[sliderAdd5:GetName() .. "Low"]:SetText("1")
  _G[sliderAdd5:GetName() .. "High"]:SetText("100")
  _G[sliderAdd5:GetName() .. "Text"]:SetText(FaceMelter:GetDeathMana())
  sliderAdd5:SetPoint("TOPRIGHT", -10, -114)

  local fstringAdd6 = FaceMelter.additionalPanel:CreateFontString("FaceMelterOptions_string4","OVERLAY","GameFontNormal")
  fstringAdd6:SetText("Player Mana to use Dispersion")
  fstringAdd6:SetPoint("TOPLEFT", 10, -140)

  local sliderAdd6 = CreateFrame("Slider", "FaceMelterOptions_Dispersion_Mana", FaceMelter.additionalPanel, "OptionsSliderTemplate")
  sliderAdd6:SetMinMaxValues(0, 100)
  sliderAdd6:SetHeight(14)
  sliderAdd6:SetValue(FaceMelter:GetDispersionMana())
  sliderAdd6:SetValueStep(1)
  sliderAdd6:SetScript("OnValueChanged", function(self) FaceMelter:SetDispersionMana(self:GetValue()); _G[self:GetName() .. "Text"]:SetText(self:GetValue()) end)
  _G[sliderAdd6:GetName() .. "Low"]:SetText("1")
  _G[sliderAdd6:GetName() .. "High"]:SetText("100")
  _G[sliderAdd6:GetName() .. "Text"]:SetText(FaceMelter:GetDispersionMana())
  sliderAdd6:SetPoint("TOPRIGHT", -10, -140)

  local fstringAdd7 = FaceMelter.additionalPanel:CreateFontString("FaceMelterOptions_string4","OVERLAY","GameFontNormal")
  fstringAdd7:SetText("DoT Refresh Tolerance (% of 1/2 DoT Tick)")
  fstringAdd7:SetPoint("TOPLEFT", 10, -166)

  local sliderAdd7 = CreateFrame("Slider", "FaceMelterOptions_DoT_Tolerance", FaceMelter.additionalPanel, "OptionsSliderTemplate")
  sliderAdd7:SetMinMaxValues(0, 100)
  sliderAdd7:SetHeight(14)
  sliderAdd7:SetValue(FaceMelter:GetDotTolerance())
  sliderAdd7:SetValueStep(1)
  sliderAdd7:SetScript("OnValueChanged", function(self) FaceMelter:SetDotTolerance(self:GetValue()); _G[self:GetName() .. "Text"]:SetText(self:GetValue()) end)
  _G[sliderAdd7:GetName() .. "Low"]:SetText("1")
  _G[sliderAdd7:GetName() .. "High"]:SetText("100")
  _G[sliderAdd7:GetName() .. "Text"]:SetText(FaceMelter:GetDotTolerance())
  sliderAdd7:SetPoint("TOPRIGHT", -10, -166)

  local fstringAdd8 = FaceMelter.additionalPanel:CreateFontString("FaceMelterOptions_string4","OVERLAY","GameFontNormal")
  fstringAdd8:SetText("Restrict Mind Blast to Empowered Shadow duration less than X sec")
  fstringAdd8:SetPoint("TOPLEFT", 10, -192)

  local fstringAdd9 = FaceMelter.additionalPanel:CreateFontString("FaceMelterOptions_string4","OVERLAY","GameFontNormal")
  fstringAdd9:SetText("(when Minimum Orbs is set to 1 or more)")
  fstringAdd9:SetPoint("TOPLEFT", 10, -218)

  local sliderAdd9 = CreateFrame("Slider", "FaceMelterOptions_Empowered_Remaining", FaceMelter.additionalPanel, "OptionsSliderTemplate")
  sliderAdd9:SetMinMaxValues(2, 10)
  sliderAdd9:SetHeight(14)
  sliderAdd9:SetValue(FaceMelter:GetEmpoweredRemaining())
  sliderAdd9:SetValueStep(1)
  sliderAdd9:SetScript("OnValueChanged", function(self) FaceMelter:SetEmpoweredRemaining(self:GetValue()); _G[self:GetName() .. "Text"]:SetText(self:GetValue()) end)
  _G[sliderAdd9:GetName() .. "Low"]:SetText("2")
  _G[sliderAdd9:GetName() .. "High"]:SetText("10")
  _G[sliderAdd9:GetName() .. "Text"]:SetText(FaceMelter:GetEmpoweredRemaining())
  sliderAdd9:SetPoint("TOPRIGHT", -10, -218)

  InterfaceOptions_AddCategory(FaceMelter.additionalPanel);

--  InterfaceAddOnsList_Update();
end

-- Slash Command
function FaceMelter.Command(msg)
  if(msg == "help" or msg == "?") then
    print("FaceMelter syntax: /facemelter [command] or /fm [command]")
    print("menu, options, (no argument)    open options menu")
    print("priorities, priority, pri       option priorities menu")
    print("spells, spell, additional, add  option spell options menu")
    print("show                            show suggester frame")
    print("hide                            hide suggester frame")
    print("toggle                          toggle suggester frame")
    print("lock, unlock                    lock/unlock suggester frame")
    print("button, buttons, boxes, box     show checkboxes on suggester frame")
    print("help, ?                         show this help message")
  elseif (msg == "menu" or msg == "options" or msg == "") then
    FaceMelter.Options()
  elseif (msg == "show") then
    facemelterdb.hideSuggester = false
    FaceMelter.UICheck:SetChecked(false)
    FaceMelter:EvalGUIShowHide()
  elseif (msg == "hide") then
    facemelterdb.hideSuggester = true
    FaceMelter.UICheck:SetChecked(true)
    FaceMelter:EvalGUIShowHide()
  elseif (msg == "toggle") then
    FaceMelter:ToggleSuggester()
  elseif (msg == "buttons" or msg == "button" or msg == "boxes" or msg == "box") then
    FaceMelter:ToggleButtons()
  elseif (msg == "priorities" or msg == "priority" or msg == "pri" ) then
    InterfaceOptionsFrame_OpenToCategory(_G["FaceMelterPriorities"])
  elseif (msg == "spell" or msg == "spells" or msg == "additional" or msg == "add" ) then
    InterfaceOptionsFrame_OpenToCategory(_G["FaceMelterAdditional"])
  elseif (msg == "lock" or msg == "unlock") then
    FaceMelter:ToggleLocked()
  end
end

function FaceMelter.Options()
  InterfaceOptionsFrame_OpenToCategory(_G["FaceMelterOptions"])
end

-- Rounding Function
function round(num, idp)
  local mult = 10^(idp or 0)
  return math.floor(num * mult + 0.5) / mult
end